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

Appearance settings

Docs: improve covariance generic typing examples #130302

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
Loading
from

Conversation

dantetemplar
Copy link

@dantetemplar dantetemplar commented Feb 19, 2025

@ghost
Copy link

ghost commented Feb 19, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app bedevere-app bot added docs Documentation in the Doc dir skip news awaiting review labels Feb 19, 2025
@dantetemplar
Copy link
Author

skip issue

@dantetemplar
Copy link
Author

dantetemplar commented Feb 19, 2025

The original documentation did not include a declaration for BasicUser, so I added one along with some additional examples

@JelleZijlstra
Copy link
Member

I don't think we need this many additional examples. Let's try to keep the examples short and focused. It may be enough to just add a class BasicUser(User): ....

@dantetemplar
Copy link
Author

I don't think we need this many additional examples. Let's try to keep the examples short and focused. It may be enough to just add a class BasicUser(User): ....

image

Let me argue, then this section does not give the reader information about how typing with inheritance will work in this case. If it’s ok, then fine, I’ll remove the unnecessary stuff.

@@ -421,8 +423,9 @@ Note that ``type[C]`` is covariant::
return user_class()

make_new_user(User) # OK
make_new_user(ProUser) # Also OK: ``type[ProUser]`` is a subtype of ``type[User]``
make_new_user(TeamUser) # Still fine
make_new_user(BasicUser) # Also OK: ``type[BasicUser]`` is a subtype of ``type[User]``
Copy link
Member

Choose a reason for hiding this comment

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

This now demonstrates the exact same thing three times. I think we only need one. We can keep one of the three subclasses in this test, and move the remaining two class definitions to the next test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.