Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Description
Feature or enhancement
When usinghelp(...), annotations should be unstringified and displayed withouttyping.ForwardRef.
Pitch
Current behavior displays string annotations with quotes as follows:
deffoo(x:List["A"],y:"B")->None: ...help(foo)"""Help on function foo in module ...:foo(x: List[ForwardRef('A')], y: 'B') -> None"""
It should be fairly obvious how clunky this is to users, and that the desirable behavior should be something like:
help(foo)"""Help on function foo in module ...:foo(x: List[A], y: B) -> None"""
#84171 is related, but whereas the suggestion there is to actually evaluate the annotations usingtyping.get_type_hints or similar, this proposal aims to only remove quotations andtyping.ForwardRef(...) from the outputted documentation.
This means that the resulting documentation may not be 100% accurate but will not require evaluating the annotation, which can avoid issues such as annotations which cannot be evaluated for some reason.
For example:
importtypingiftyping.TYPE_CHECKING:importnumpyasnpdeffoo(x:"np.ndarray")->None: ...help(foo)"""Help on function foo in module ...:foo(x: np.ndarray) -> None"""
Note that thenp.ndarray is not expanded out into its fully qualified namenumpy.ndarray.
There are also some additional edge cases to consider, such as"ForwardRef('A')". Ideally this should be changed toA, but I don't think there's much impact if it is purposefully left as that, and leaving it as-is avoids other problems e.g.ForwardRef is not actuallytyping.ForwardRef in that example.