- I am new to Django and come from Java/Spring background.
- I am wondering if there are decorators something like following that can be done in Django or Python?
Want
def addToList(@not_none a, @not_none b):
# so that I do not check for nullity explicitly
do_things_with_a(a)
do_things_with_b(b)
- Since this is something which is pretty easy to get in Java, just looking if Python/Django has it
One doesn’t typically constraint data-types in Python. Also, decorators can only be applied to classes and to methods/functions.
Although, you shouldn’t really be doing this, this is how you would.
(You could amend this to accept argument names to enforce constraints on with a little work).