With PEP-563, it is legal to annotate a function as follows
deffoo(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.
Activity
McSinyx commented on Mar 17, 2020
With PEP-563, it is legal to annotate a function as follows
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.
McSinyx commented on Mar 17, 2020
I traced it down to inspect.formatannotation(annotation). Before checking for isinstance(annotation, type), IMHO we should do something like
However, is is not aware of globals and especially locals of help caller, so I guess more sophisticated solution is required.
FFY00 commented on May 3, 2020
typing.get_type_hints can be used for this, it resolves the annotation string.
JelleZijlstra commented on Nov 17, 2024
This is fixed in 3.14 thanks to some of the PEP-649 changes. Using the OP's example: