-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-81677: basic support for annotations in __text_signature__'s #101872
base: main
Are you sure you want to change the base?
Conversation
57df8d4
to
1875758
Compare
@sobolevn, maybe you could review this (at least the inspect part)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
Couple of thoughts:
- Does anyone actually use
__text_annotations__
? (I am asking because I don't know). I assume people use it, is it a breaking change for them? - How well does your solution support more complex annotations that require (a)
typing
imports, what we might need from there? (b) forward references and https://peps.python.org/pep-0649/
Other than that - I don't really have an opinion on this feature. Because I don't any real use-cases for it.
I can't find any example outside of the CPython, and it's not documented (as the Clearly, it might be useful for extensions.
No, I don't think so. Previously, the return annotation was just ignored and if there were parameter annotations - an exception was raised.
This solution does assume application in the stdlib modules and simple extensions (e.g. I've tested this on the gmpy2), so
Any example of using |
fa40691
to
9c11c50
Compare
@1st1, you are listed as an expert for the inspect module. Maybe you could review this little pr? |
a93577f
to
3c23b22
Compare
PEP waiting for a sponsor: skirpichev/peps#2 |
… inspect.signature()
This is an alternative to python#100168.
…string" This reverts commit 3dc4125.
…hods" This reverts commit ff758ab.
…_ attribute" This reverts commit 1f3c7f3.
Ok, it seems nobody like to sponsor PEP, so I'm returning PR to initial shape (that address review). This is ready for review again. |
Have you posted the draft PEP on discuss.python.org? It may have been missed here... A |
Yes, that was posted in the thread, discussing this pr, there. |
__text_signature__
properties. Mostly naive and minimal implementation: there could be some validation of parsed annotations (e.g. to exclude something likeprint(1)
).But I doubt, that this is required. In fact, probably the whole method could be refactored to do first parsing the
program
string, then do ast transformation (RewriteSymbolics
) for defaults, then doast.unparse()
, eval its output and use_signature_from_function()
helper to get the final result.PyDoc_STRVAR
. Before - only([<python-style parameter_list>])
was accepted. Now it permits everything till the end marker (\n--\n\n
), that allows us tospecify return annotations. (A first step to something like Support return annotation in signature for Argument Clinic #76120.)
This doesn't touch public interfaces: the
__text_signature__
property left undocumented (but see #93865).