-
-
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
Support annotations in signature strings. #81677
Comments
In early 2014 (3.3), when argument clinic was added, we added support for turning func.__text_signature__ into an inspect.Signature object. However, at that time we did not add support for annotations (see the nested "parse_name()" in _signature_fromstr(). Annotations should be supported. I'd expect that PEP-563 (Postponed Evaluation of Annotations) could be leveraged. |
I'd like to work on this, but I'm kind of new to the codebase. Do you think I should leave this task to someone more expert on the matter? I took a look at the function you mentioned and I was able to support simple annotations, for instance Do you have any suggestion for how to continue working on this task? |
You might want to look into how PEP-563 is implemented, it has a utility to turn an AST back into a string (I assume this is what you want). |
+1 on using a string for Parameter.annotation and Signature.return_annotation. |
Thanks for your suggestion @levkivskyi. I took a look at #4390, that implements PEP-563. In that PR
Source: #4390 (comment) I have a couple of questions about how to use
On a side note: would it make sense to reconcile the two "unparse AST" implementations?
Thanks for your comment @eric.snow. From what I saw in the test I've written, right now At the beginning, in order to keep Returning strings would make |
Hm, TBH I am not sure which one is better, I am leaning towards option 1, but I add more people to get some opinions. |
I would vote for #1. If it is not up to the task that probably points to a flaw anyway. |
We have exposed Tools/unparse.py under ast module, so that option also can help. @potomak are you still interested in working on this issue? |
Thanks for the info. Yes, I’m still interested in working on the issue, but lately I didn’t have If this is a high priority feel free to re-assign to someone else, On Sun, Dec 1, 2019 at 6:59 AM Batuhan <[email protected]> wrote:
|
This seems somewhat related to https://bugs.python.org/issue31939 |
It seems nobody is working on this issue, so I'll try in #101872. |
I think that's @ericsnowcurrently's call, as he filed the issue. |
I don't recall having any need for this, nor do I recall why I opened this issue. It does still make sense to me that we would support annotations in Also, note that support for annotations in signature strings extends beyond
...the implementation does further computations, including handling a string (even if imperfectly): Lines 2520 to 2521 in 53b84e7
So I think this issue should stay open unless we don't plan on fully supporting |
I did this in #101872 (now this pr has several commits more, after 177c993, needed for my PEP draft), but @encukou was against this.
BTW, making string processing public wasn't part of this proposal or #101872.
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: