Skip to content

gh-101688: Implement types.get_original_bases #101827

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

Merged
merged 45 commits into from
Apr 23, 2023

Conversation

Gobot1234
Copy link
Contributor

@Gobot1234 Gobot1234 commented Feb 11, 2023

Implements the methods described.

A couple of questions:

  • Should there be checking of the return types of the functions since they could be anything?
  • Should we add __orig_class__ to the slots of all the types that currently don't have them to provide better introspection support (currently get_orig_class(list[int]()) is None)

@arhadthedev arhadthedev added stdlib Python modules in the Lib dir topic-typing labels Feb 11, 2023
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Gobot1234
Copy link
Contributor Author

Error looks unrelated?

@sobolevn
Copy link
Member

Yes, it is.

@Gobot1234 Gobot1234 changed the title gh-101688: Implement typing.get_orig_class and get_orig_bases gh-101688: Implement typing.get_orig_class and types.get_orig_bases Feb 25, 2023
Gobot1234 and others added 2 commits April 12, 2023 22:04
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@AlexWaygood
Copy link
Member

@gvanrossum, how's this look to you now? Any more suggestions re. the docs?

@AlexWaygood AlexWaygood requested a review from gvanrossum April 22, 2023 22:47
@gvanrossum
Copy link
Member

Who is musashay? Spammer? Bot?

@AlexWaygood
Copy link
Member

Who is musashay? Spammer? Bot?

No idea

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not excited about the use of assert. Do we do this often in other examples?

@Gobot1234
Copy link
Contributor Author

Still not excited about the use of assert. Do we do this often in other examples?

It seems to show up in a couple of other places https://github.com/search?q=repo%3Apython%2Fcpython+lang%3ARST+assert&type=code

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 22, 2023

Still not excited about the use of assert. Do we do this often in other examples?

I feel like the closest stdlib analogues to this function are typing.get_args and typing.get_origin, and it's what we do there:

cpython/Doc/library/typing.rst

Lines 2878 to 2882 in 7bf9456

assert get_origin(Dict[str, int]) is dict
assert get_args(Dict[int, str]) == (int, str)
assert get_origin(Union[int, str]) is Union
assert get_args(Union[int, str]) == (int, str)

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sold.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant to approve.

@AlexWaygood
Copy link
Member

I'll merge once the CI finishes.

@AlexWaygood AlexWaygood merged commit 730bbdd into python:main Apr 23, 2023
@AlexWaygood
Copy link
Member

@Gobot1234, are you up for adding a stub to typeshed and backporting it to typing_extensions? I can probably take a look soon, if you haven't got the time.

@Gobot1234
Copy link
Contributor Author

I can probably do the typeshed stub tonight but I don't know when I'll get to the typing extensions backport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 only security fixes stdlib Python modules in the Lib dir topic-typing type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants