-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
help should evaluate forward reference #84171
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
Comments
With PEP-563, it is legal to annotate a function as follows def foo(bar: 'int') -> 'bool': pass Currently, help(foo) would print the exact signature in foo.__annotations__ and it's not really pretty. My proposal is to use the type hints from typing.get_type_hints to make documentations more readable from the user's perspective. I might not be aware of all use cases and disadvantages of this proposal however. |
I traced it down to inspect.formatannotation(annotation). Before checking for isinstance(annotation, type), IMHO we should do something like import typing
if isinstance(annotation, str):
annotation = typing.ForwardRef(str)._evaluate(annotation) However, is is not aware of globals and especially locals of help caller, so I guess more sophisticated solution is required. |
typing.get_type_hints can be used for this, it resolves the annotation string. >>> def foo(bar: 'int') -> 'bool': pass
...
>>> typing.get_type_hints(foo)
{'bar': <class 'int'>, 'return': <class 'bool'>} |
This is fixed in 3.14 thanks to some of the PEP-649 changes. Using the OP's example:
|
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:
The text was updated successfully, but these errors were encountered: