@@ -5022,8 +5022,10 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
50225022 str | None == typing.Optional[str]
50235023
50245024.. describe :: isinstance(obj, union_object)
5025+ .. describe :: issubclass(obj, union_object)
50255026
5026- Calls to :func: `isinstance ` are also supported with a union object::
5027+ Calls to :func: `isinstance ` and :func: `issubclass ` are also supported with a
5028+ union object::
50275029
50285030 >>> isinstance("", int | str)
50295031 True
@@ -5036,21 +5038,6 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
50365038 File "<stdin>", line 1, in <module>
50375039 TypeError: isinstance() argument 2 cannot contain a parameterized generic
50385040
5039- .. describe :: issubclass(obj, union_object)
5040-
5041- Calls to :func: `issubclass ` are also supported with a union object::
5042-
5043- >>> issubclass(bool, int | str)
5044- True
5045-
5046- However, union objects containing :ref: `parameterized generics
5047- <types-genericalias>` cannot be used::
5048-
5049- >>> issubclass (bool , bool | list[str ])
5050- Traceback (most recent call last):
5051- File "<stdin>", line 1, in <module>
5052- TypeError: issubclass() argument 2 cannot contain a parameterized generic
5053-
50545041The user-exposed type for the union object can be accessed from
50555042:data: `types.Union ` and used for :func: `isinstance ` checks. An object cannot be
50565043instantiated from the type::
0 commit comments