@@ -508,6 +508,14 @@ The module defines the following classes, functions and decorators:
508
508
509
509
An ABC with one abstract method ``__float__ ``.
510
510
511
+ .. class :: SupportsComplex
512
+
513
+ An ABC with one abstract method ``__complex__ ``.
514
+
515
+ .. class :: SupportsBytes
516
+
517
+ An ABC with one abstract method ``__bytes__ ``.
518
+
511
519
.. class :: SupportsAbs
512
520
513
521
An ABC with one abstract method ``__abs__ `` that is covariant
@@ -658,7 +666,19 @@ The module defines the following classes, functions and decorators:
658
666
659
667
.. class :: DefaultDict(collections.defaultdict, MutableMapping[KT, VT])
660
668
661
- A generic version of :class: `collections.defaultdict `
669
+ A generic version of :class: `collections.defaultdict `.
670
+
671
+ .. class :: Counter(collections.Counter, Dict[T, int])
672
+
673
+ A generic version of :class: `collections.Counter `.
674
+
675
+ .. versionadded :: 3.6.1
676
+
677
+ .. class :: ChainMap(collections.ChainMap, MutableMapping[KT, VT])
678
+
679
+ A generic version of :class: `collections.ChainMap `.
680
+
681
+ .. versionadded :: 3.6.1
662
682
663
683
.. class :: Generator(Iterator[T_co], Generic[T_co, T_contra, V_co])
664
684
@@ -742,9 +762,12 @@ The module defines the following classes, functions and decorators:
742
762
743
763
This defines the generic type ``IO[AnyStr] `` and aliases ``TextIO ``
744
764
and ``BinaryIO `` for respectively ``IO[str] `` and ``IO[bytes] ``.
745
- These representing the types of I/O streams such as returned by
765
+ These represent the types of I/O streams such as returned by
746
766
:func: `open `.
747
767
768
+ These types are also accessible directly as ``typing.IO ``,
769
+ ``typing.TextIO ``, and ``typing.BinaryIO ``.
770
+
748
771
.. class :: re
749
772
750
773
Wrapper namespace for regular expression matching types.
@@ -756,6 +779,9 @@ The module defines the following classes, functions and decorators:
756
779
``Pattern[str] ``, ``Pattern[bytes] ``, ``Match[str] ``, or
757
780
``Match[bytes] ``.
758
781
782
+ These types are also accessible directly as ``typing.Pattern ``
783
+ and ``typing.Match ``.
784
+
759
785
.. class :: NamedTuple
760
786
761
787
Typed version of namedtuple.
@@ -782,10 +808,20 @@ The module defines the following classes, functions and decorators:
782
808
Fields with a default value must come after any fields without a default.
783
809
784
810
The resulting class has two extra attributes: ``_field_types ``,
785
- giving a dict mapping field names to types, and ``field_defaults ``, a dict
811
+ giving a dict mapping field names to types, and ``_field_defaults ``, a dict
786
812
mapping field names to default values. (The field names are in the
787
813
``_fields `` attribute, which is part of the namedtuple API.)
788
814
815
+ ``NamedTuple `` subclasses can also have docstrings and methods::
816
+
817
+ class Employee(NamedTuple):
818
+ """Represents an employee."""
819
+ name: str
820
+ id: int = 3
821
+
822
+ def __repr__(self) -> str:
823
+ return f'<Employee {self.name}, id={self.id}>'
824
+
789
825
Backward-compatible usage::
790
826
791
827
Employee = NamedTuple('Employee', [('name', str), ('id', int)])
@@ -794,7 +830,7 @@ The module defines the following classes, functions and decorators:
794
830
Added support for :pep: `526 ` variable annotation syntax.
795
831
796
832
.. versionchanged :: 3.6.1
797
- Added support for default values.
833
+ Added support for default values, methods, and docstrings .
798
834
799
835
.. function :: NewType(typ)
800
836
@@ -972,9 +1008,9 @@ The module defines the following classes, functions and decorators:
972
1008
973
1009
:data: `ClassVar ` is not a class itself, and should not
974
1010
be used with :func: `isinstance ` or :func: `issubclass `.
975
- Note that :data: `ClassVar ` does not change Python runtime behavior;
976
- it can be used by 3rd party type checkers, so that the following
977
- code might flagged as an error by those ::
1011
+ :data: `ClassVar ` does not change Python runtime behavior, but
1012
+ it can be used by third- party type checkers. For example, a type checker
1013
+ might flag the following code as an error::
978
1014
979
1015
enterprise_d = Starship(3000)
980
1016
enterprise_d.stats = {} # Error, setting class variable on instance
0 commit comments