@NotNull, @Nullable (by jetbrains) in Java: https://www.jetbrains.com/hel...
It can be implemented using decorators in Python, but no fine-grained control has been found yet: https://www.google.com/search...
Hope to provide a kind of fine-grained control, that is: specific control of each parameter
Only want to check the null pointer, no type qualification
Manual, cumbersome writing method
def func(param1, param2, param3):
# 明确表示, 不接受空指针(这里写法很繁琐, 是否有简化方法?)
if not ((param1 is not None) and (param2 is not None) and (param3 is not None)):
raise TypeError('%s or %s or %s is None' % (param1, param2, param3))
# 正常函数逻辑
How to write the decorator (not implemented)
@not_null(param1, param2)
def func(param1, param2, param3, *args, **kw):
Python 3.5