-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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
base: main
Are you sure you want to change the base?
Conversation
skip issue |
The original documentation did not include a declaration for |
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 |
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]`` |
There was a problem hiding this comment.
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.
📚 Documentation preview 📚: https://cpython-previews--130302.org.readthedocs.build/