8000 Add back `origin_is_union()` · pydantic/pydantic@2b21340 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b21340

Browse files
committed
Add back origin_is_union()
pydantic-settings relies on it.
1 parent 343bef3 commit 2b21340

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pydantic/_internal/_typing_extra.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,27 @@ def is_namedtuple(tp: Any, /) -> bool:
182182
return lenient_issubclass(tp, tuple) and hasattr(tp, '_fields')
183183

184184

185+
# TODO In 2.12, delete this function. It is currently defined only to not break
186+
# pydantic-settings which relies on it:
187+
_t_union = typing.Union
188+
_te_union = typing_extensions.Union
189+
190+
_t_union = typing.Union
191+
_te_union = typing_extensions.Union
192+
193+
if sys.version_info >= (3, 10):
194+
195+
def origin_is_union(tp: Any, /) -> bool:
196+
"""Return whether the provided argument is the `Union` special form or the `UnionType`."""
197+
return tp is _t_union or tp is _te_union or tp is types.UnionType
198+
199+
else:
200+
201+
def origin_is_union(tp: Any, /) -> bool:
202+
"""Return whether the provided argument is the `Union` special form."""
203+
return tp is _t_union or tp is _te_union
204+
205+
185206
def is_generic_alias(tp: Any, /) -> bool:
186207
return isinstance(tp, (types.GenericAlias, typing._GenericAlias)) # pyright: ignore[reportAttributeAccessIssue]
187208

0 commit comments

Comments
 (0)
0