On Sun, Oct 31, 2021 at 7:01 PM Jonathan Fine <jfine2...@gmail.com> wrote:
>
> 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'.

Interesting. How's it going to do that? What's it going to look at in
the function to find a bare string? They get completely optimized out
during compilation.

> 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.

That's one small part of it. You haven't improved the signature, you
haven't removed the need for sentinels, but you have at least added
some source code to help(fn). Assuming that the source code is indeed
available, that is; wouldn't work if the function came from a .pyc
file.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/F4TF5CEP6HPPAYALJXQN2A7ZSFRDBMO7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to