Skip to content
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

typing.get_type_hints documentation claims it no longer includes base class type hints. #100673

Closed
FrozenBob opened this issue Jan 2, 2023 · 4 comments · Fixed by #100826
Closed
Labels
docs Documentation in the Doc dir topic-typing

Comments

@FrozenBob
Copy link
Contributor

FrozenBob commented Jan 2, 2023

Documentation

The typing.get_type_hints documentation currently says

Changed in version 3.10: Calling get_type_hints() on a class no longer returns the annotations of its base classes.

This is incorrect. No such change was made in 3.10, and no such change should be made. The documentation was changed erroneously when someone mixed up the typing.get_type_hints behavior with an unrelated __annotations__ change.

This note should be removed from the typing.get_type_hints documentation.

Linked PRs

@FrozenBob FrozenBob added the docs Documentation in the Doc dir label Jan 2, 2023
@hauntsaninja
Copy link
Contributor

hauntsaninja commented Jan 2, 2023

Thanks for catching, that sounds right to me. Want to open a PR to remove it?

E.g. easy to confirm that the following extension of the test added in that PR has the same typing.get_type_hints output on Python 3.9, 3.10.9, 3.11.1, main.

class A:
    attr: int
class B(A):
    pass
class C(A):
    attr: str
class D:
    attr2: int
class E(A, D):
    pass
class F(C, A):
    pass

print(A.__annotations__)
print(B.__annotations__)
print(C.__annotations__)
print(D.__annotations__)
print(E.__annotations__)
print(F.__annotations__)
print("=" * 40)

import typing
print(typing.get_type_hints(A))
print(typing.get_type_hints(B))
print(typing.get_type_hints(C))
print(typing.get_type_hints(D))
print(typing.get_type_hints(E))
print(typing.get_type_hints(F))

@FrozenBob
Copy link
Contributor Author

Seems straightforward, and I've got a commit I could create a pull request for, but I don't have a dev environment set up to be able to build the docs or run stuff like patchcheck. If I screw something up somehow, I might not notice.

@hauntsaninja
Copy link
Contributor

That commit looks good to me. Open the PR and I'll take care of the rest :-)

AlexWaygood pushed a commit that referenced this issue Jan 7, 2023
Removed erroneous note in the get_type_hints docs

typing.get_type_hints still includes base class type hints.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jan 7, 2023
…ythonGH-100701)

Removed erroneous note in the get_type_hints docs

typing.get_type_hints still includes base class type hints.
(cherry picked from commit deaf090)

Co-authored-by: FrozenBob <[email protected]>
miss-islington added a commit that referenced this issue Jan 7, 2023
Removed erroneous note in the get_type_hints docs

typing.get_type_hints still includes base class type hints.
(cherry picked from commit deaf090)

Co-authored-by: FrozenBob <[email protected]>
AlexWaygood pushed a commit to AlexWaygood/cpython that referenced this issue Jan 7, 2023
…ython#100701)

Removed erroneous note in the get_type_hints docs

typing.get_type_hints still includes base class type hints.

(cherry picked from commit deaf090)
miss-islington pushed a commit that referenced this issue Jan 7, 2023
…100701) (GH-100826)

Removed erroneous note in the get_type_hints docs

typing.get_type_hints still includes base class type hints.

(cherry picked from commit deaf090)

Automerge-Triggered-By: GH:AlexWaygood
@hauntsaninja
Copy link
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir topic-typing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants