File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -497,7 +497,8 @@ Module contents
497497.. function :: is_dataclass(obj)
498498
499499 Return ``True `` if its parameter is a dataclass (including subclasses of a
500- dataclass) or an instance of one, otherwise return ``False ``.
500+ dataclass, but not including :ref: `generic aliases <types-genericalias >`)
501+ or an instance of one, otherwise return ``False ``.
501502
502503 If you need to know if a class is an instance of a dataclass (and
503504 not a dataclass itself), then add a further check for ``not
Original file line number Diff line number Diff line change @@ -399,6 +399,9 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
399399 Return ``True `` if the object is a class, whether built-in or created in Python
400400 code.
401401
402+ This function returns ``False `` for :ref: `generic aliases <types-genericalias >` of classes,
403+ such as ``list[int] ``.
404+
402405
403406.. function :: ismethod(object)
404407
Original file line number Diff line number Diff line change @@ -5783,7 +5783,8 @@ type and the :class:`bytes` data type:
57835783
57845784``GenericAlias `` objects are instances of the class
57855785:class: `types.GenericAlias `, which can also be used to create ``GenericAlias ``
5786- objects directly.
5786+ objects directly. Specializations of user-defined :ref: `generic classes <generic-classes >`
5787+ may not be instances of :class: `types.GenericAlias `, but they provide similar functionality.
57875788
57885789.. describe :: T[X, Y, ...]
57895790
Original file line number Diff line number Diff line change @@ -3480,14 +3480,27 @@ Introspection helpers
34803480
34813481 Determine if a type is a :class: `Protocol `.
34823482
3483- For example::
3483+ For example:
3484+
3485+ .. testcode ::
34843486
34853487 class P(Protocol):
34863488 def a(self) -> str: ...
34873489 b: int
34883490
3489- is_protocol(P) # => True
3490- is_protocol(int) # => False
3491+ assert is_protocol(P)
3492+ assert not is_protocol(int)
3493+
3494+ This function only returns true for ``Protocol `` classes, not for
3495+ :ref: `generic aliases <types-genericalias >` of them:
3496+
3497+ .. testcode ::
3498+
3499+ class GenericP[T](Protocol):
3500+ def a(self) -> T: ...
3501+ b: int
3502+
3503+ assert not is_protocol(GenericP[int])
34913504
34923505 .. versionadded :: 3.13
34933506
@@ -3510,6 +3523,17 @@ Introspection helpers
35103523 # not a typed dict itself
35113524 assert not is_typeddict(TypedDict)
35123525
3526+ This function only returns true for ``TypedDict `` classes, not for
3527+ :ref: `generic aliases <types-genericalias >` of them:
3528+
3529+ .. testcode ::
3530+
3531+ class GenericFilm[T](TypedDict):
3532+ title: str
3533+ year: T
3534+
3535+ assert not is_typeddict(GenericFilm[int])
3536+
35133537 .. versionadded :: 3.10
35143538
35153539.. class :: ForwardRef
You can’t perform that action at this time.
0 commit comments