Here is a little trick to catch functions or methods that you haven't
implemented yet. It's useful when you sketch out the structure of a
program but the functions/methods don't do anything yet. Typically you
write the signature of the function but the only line of code is pass.
The last line of the function must be pass for this to work.
import inspect
import sys
def notImplemented(f):
"""Decorator to announce when the decorated function has
not been implemented. The last line of the function
must be "pass" for this to work.
"""
_name = f.__name__
def new_f(*args):
_lines = inspect.getsourcelines(f)[0]
if _lines[-1].strip() == 'pass' :
print(f'{_name} not implemented')
sys.exit(2)
else:
return f(*args)
return new_f
Typical usage:
@notImpemented
def func1(arg1, arg2):
"""A function in the middle of being developed."""
for s in arg1:
words = s.split()
# we're still working on it, more to come tomorrow
pass # Comment out this line when you work on the code
Now when you try to run your program, the output will politely tell you
which function you called but you forgot that it isn't finished yet.
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/ccbb9662-f9a7-4f67-a23f-b94f439f1ec7n%40googlegroups.com.