Skip to content

Commit

Permalink
Add local copy of is_type_alias_type.
Browse files Browse the repository at this point in the history
  • Loading branch information
kschwab committed Feb 25, 2025
1 parent 5cdeee5 commit 605cc75
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pydantic_settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from dotenv import dotenv_values
from pydantic import AliasChoices, AliasPath, BaseModel, Json, RootModel, Secret, TypeAdapter
from pydantic._internal._repr import Representation
from pydantic._internal._typing_extra import WithArgsTypes, is_type_alias_type, origin_is_union, typing_base
from pydantic._internal._typing_extra import WithArgsTypes, origin_is_union, typing_base
from pydantic._internal._utils import deep_update, is_model_class, lenient_issubclass
from pydantic.dataclasses import is_pydantic_dataclass
from pydantic.fields import FieldInfo
Expand Down Expand Up @@ -1986,7 +1986,7 @@ def _metavar_format_recurse(self, obj: Any) -> str:
return '...'
elif isinstance(obj, Representation):
return repr(obj)
elif isinstance(obj, typing.ForwardRef) or is_type_alias_type(obj):
elif isinstance(obj, typing.ForwardRef) or _is_type_alias_type(obj):
return str(obj)

if not isinstance(obj, (typing_base, WithArgsTypes, type)):
Expand Down Expand Up @@ -2425,3 +2425,17 @@ def _get_alias_names(

def _is_function(obj: Any) -> bool:
return isinstance(obj, (FunctionType, BuiltinFunctionType))


# _TYPE_ALIAS_TYPES is copied from `pydantic._internal._typing_extra`.
_TYPE_ALIAS_TYPES: tuple[type[typing_extensions.TypeAliasType], ...] = (typing_extensions.TypeAliasType,)
if sys.version_info >= (3, 12):
_TYPE_ALIAS_TYPES = (*_TYPE_ALIAS_TYPES, typing.TypeAliasType)


def _is_type_alias_type(tp: Any, /) -> typing_extensions.TypeIs[typing_extensions.TypeAliasType]:
"""
Return whether the provided argument is an instance of `TypeAliasType`.
Copied from `pydantic._internal._typing_extra`.
"""
return isinstance(tp, _TYPE_ALIAS_TYPES)

0 comments on commit 605cc75

Please sign in to comment.