-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature[next]: support for Python 3.11 #1407
Changes from 6 commits
b32df9c
7b79e19
25e7466
a6008f8
70c0b44
da6507b
2b510d6
bcc4f0e
d34836f
af92ac1
10ebae1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -971,6 +971,14 @@ def __pretty__( | |
return __pretty__ | ||
|
||
|
||
def _is_concrete_data_model( | ||
cls: Type, type_args: Tuple[Type] | ||
) -> typing.TypeGuard[Type[DataModelT]]: | ||
return hasattr(cls, "__bound_type_params__") and all( | ||
a == b for a, b in zip(cls.__bound_type_params__.values(), type_args) | ||
) | ||
|
||
|
||
def _make_data_model_class_getitem() -> classmethod: | ||
def __class_getitem__( | ||
cls: Type[GenericDataModelT], args: Union[Type, Tuple[Type]] | ||
|
@@ -980,7 +988,9 @@ def __class_getitem__( | |
See :class:`GenericDataModelAlias` for further information. | ||
""" | ||
type_args: Tuple[Type] = args if isinstance(args, tuple) else (args,) | ||
concrete_cls: Type[DataModelT] = concretize(cls, *type_args) | ||
concrete_cls: Type[DataModelT] = ( | ||
cls if _is_concrete_data_model(cls, type_args) else concretize(cls, *type_args) | ||
) | ||
res = xtyping.StdGenericAliasType(concrete_cls, type_args) | ||
if sys.version_info < (3, 9): | ||
# in Python 3.8, xtyping.StdGenericAliasType (aka typing._GenericAlias) | ||
|
@@ -1348,9 +1358,14 @@ def _make_concrete_with_cache( | |
|
||
class_name = f"{datamodel_cls.__name__}__{'_'.join(arg_names)}" | ||
|
||
bound_type_params = { | ||
tp_var.__name__: type_params_map[tp_var] for tp_var in datamodel_cls.__parameters__ | ||
} | ||
|
||
namespace = { | ||
"__annotations__": new_annotations, | ||
"__module__": module if module else datamodel_cls.__module__, | ||
"__bound_type_params__": bound_type_params, # TODO(havogt) is this useful information? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if it's useful to store this, it allows to do the check above |
||
**new_field_c_attrs, | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,6 +358,8 @@ def make_is_instance_of(name: str, type_: type) -> FixedTypeValidator: | |
"""Create an ``FixedTypeValidator`` validator for a specific type.""" | ||
|
||
def _is_instance_of(value: Any, **kwargs: Any) -> None: | ||
if type_ is Any: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. possibly tests are wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The actual reason for this was actually a bug in a previous fix for dealing with the implementation of |
||
return | ||
if not isinstance(value, type_): | ||
raise TypeError( | ||
f"'{name}' must be {type_} (got '{value}' which is a {type(value)})." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
cls: Type
, we need to do more checks inside, try againType[GenericDataModelT]