Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The builtinhelp(...) should unstringify (and "unforwardref") annotations #101552

Closed
Labels
@SimpleArt

Description

@SimpleArt

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.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp