Hi
I've just had a brainwave that may give an even less invasive
implementation of PEP 671. It relies on every function having a dict, as
provided by https://www.python.org/dev/peps/pep-0232/.
Consider:
def fn(a, b, c): pass
fn.__wibble__ = 123
fn.__wibble__ # Give 123, of course.
Now consider:
@wibble
def fn(a, b, c=None):
'''Usual docstring goes here.'''
if c is None: c = []
'#wibble'
return c.extend([a, b])
The @wibble decorator sets fn.__wibble__ to point to the end of the line
just before '#wibble'.
We can now define Help(fn) to produce something like:
fn(a, b, c=None)
Usual docstring goes here.
--
if c is None: c = []
There we go. The functionality asked for, in a way that works with existing
Python. If nothing else, we can use this for experiments to explore the
idea. Often in Python there are functions whose source is self-explanatory.
Example:
@wibble
def fahr_to_cent(fahr):
return (fahr - 32) * 5 /9
'#wibble'
And now for Help(fahr_to_cent) we get:
fahr_to_cent(fahr)
--
return (fahr - 32) * 5 /9
Final word. Does anyone use PEP 232, function attributes? If not, perhaps
remove it as a waste of space.
with kind regards
Jonathan
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/JHZVHUXV4EU57HHPBVU2EL2U33BIZ2DG/
Code of Conduct: http://python.org/psf/codeofconduct/