8000 Clarify some behavior around user-defined generic classes by rchen152 · Pull Request #1879 · python/typing · GitHub
[go: up one dir, main page]

Skip to content

Clarify some behavior around user-defined generic classes #1879

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 8 commits into from
Nov 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Mention inheriting from a generic in ways to define a class as generic.
  • Loading branch information
rchen152 committed Nov 20, 2024
commit 8d7c1d93eae32b16eedd9258e04a1489bde226cb
13 changes: 8 additions & 5 deletions docs/spec/generics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ This is equivalent to omitting the generic notation and just saying
User-defined generic types
--------------------------

You can define a user-defined class as generic in three ways: by including a
``Generic`` base class, by using the new generic class syntax in Python 3.12
and higher, or by including a ``Protocol`` base class parameterized with type
variables. The third approach also marks the class as a protocol - see
:ref:`generic protocols<generic-protocols>` for more information.
There are several ways to define a user-defined class as generic:

* Include a ``Generic`` base class.
* Use the new generic class syntax in Python 3.12 and higher.
* Include a `` Protocol`` base class parameterized with type variables. This
approach also marks the class as a protocol - see
:ref:`generic protocols<generic-protocols>` for more information.
* Include a generic base class parameterized with type variables.

Example using ``Generic``::

Expand Down
0