pydoc > typing.Generic

Help on class Generic in typing:

typing.Generic = class Generic(builtins.object)
 |  Abstract base class for generic types.
 |
 |  On Python 3.12 and newer, generic classes implicitly inherit from
 |  Generic when they declare a parameter list after the class's name::
 |
 |      class Mapping[KT, VT]:
 |          def __getitem__(self, key: KT) -> VT:
 |              ...
 |          # Etc.
 |
 |  On older versions of Python, however, generic classes have to
 |  explicitly inherit from Generic.
 |
 |  After a class has been declared to be generic, it can then be used as
 |  follows::
 |
 |      def lookup_name[KT, VT](mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
 |          try:
 |              return mapping[key]
 |          except KeyError:
 |              return default
 |
 |  Class methods defined here:
 |
 |  __class_getitem__(...)
 |      Parameterizes a generic class.
 |
 |      At least, parameterizing a generic class is the *main* thing this
 |      method does. For example, for some generic class `Foo`, this is called
 |      when we do `Foo[int]` - there, with `cls=Foo` and `params=int`.
 |
 |      However, note that this method is also called when defining generic
 |      classes in the first place with `class Foo[T]: ...`.
 |
 |  __init_subclass__(...)
 |      Function to initialize subclasses.

Generated by phpman v4.12.29 · Markdown · JSON Author: Che Dong Under GNU General Public License
2026-12-04 12:27 @216.73.216.5
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!