Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion Doc/library/dataclasses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ Module contents
.. function:: is_dataclass(obj)

Return ``True`` if its parameter is a dataclass (including subclasses of a
dataclass) or an instance of one, otherwise return ``False``.
dataclass, but not including :ref:`generic aliases <types-genericalias>`)
or an instance of one, otherwise return ``False``.

If you need to know if a class is an instance of a dataclass (and
not a dataclass itself), then add a further check for ``not
Expand Down
3 changes: 3 additions & 0 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
Return ``True`` if the object is a class, whether built-in or created in Python
code.

This function returns ``False`` for :ref:`generic aliases <types-genericalias>` of classes,
such as ``list[int]``.


.. function:: ismethod(object)

Expand Down
3 changes: 2 additions & 1 deletion Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5858,7 +5858,8 @@ type and the :class:`bytes` data type:

``GenericAlias`` objects are instances of the class
:class:`types.GenericAlias`, which can also be used to create ``GenericAlias``
objects directly.
objects directly. Specializations of user-defined :ref:`generic classes <generic-classes>`
may not be instances of :class:`types.GenericAlias`, but they provide similar functionality.

.. describe:: T[X, Y, ...]

Expand Down
30 changes: 27 additions & 3 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3633,14 +3633,27 @@ Introspection helpers

Determine if a type is a :class:`Protocol`.

For example::
For example:

.. testcode::

class P(Protocol):
def a(self) -> str: ...
b: int

is_protocol(P) # => True
is_protocol(int) # => False
assert is_protocol(P)
assert not is_protocol(int)

This function only returns true for ``Protocol`` classes, not for
:ref:`generic aliases <types-genericalias>` of them:

.. testcode::

class GenericP[T](Protocol):
Comment thread
JelleZijlstra marked this conversation as resolved.
def a(self) -> T: ...
b: int

assert not is_protocol(GenericP[int])

.. versionadded:: 3.13

Expand All @@ -3663,6 +3676,17 @@ Introspection helpers
# not a typed dict itself
assert not is_typeddict(TypedDict)

This function only returns true for ``TypedDict`` classes, not for
:ref:`generic aliases <types-genericalias>` of them:

.. testcode::

class GenericFilm[T](TypedDict):
Comment thread
JelleZijlstra marked this conversation as resolved.
title: str
year: T

assert not is_typeddict(GenericFilm[int])

.. versionadded:: 3.10

.. class:: ForwardRef
Expand Down
Loading