Skip to content

Commit d47ff1b

Browse files
committed
fixed ModelMetaclass.__new__() failing to correctly inferred that type is Group when default value is of type Group
1 parent fcf8138 commit d47ff1b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

larray/core/checked.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from larray.core.metadata import Metadata
1010
from larray.core.axis import AxisCollection
11+
from larray.core.group import Group
1112
from larray.core.array import Array, full
1213
from larray.core.session import Session
1314

@@ -173,7 +174,10 @@ def __new__(mcs, name, bases, namespace, **kwargs):
173174
if (var_name not in annotations and not var_name.startswith('_') and
174175
not isinstance(value, untouched_types) and var_name not in class_vars):
175176
validate_field_name(bases, var_name)
176-
inferred = ModelField.infer(name=var_name, value=value, annotation=annotations.get(var_name),
177+
# the method ModelField.infer() fails to infer the type of Group objects
178+
# (which are interpreted as ndarray objects)
179+
annotation = type(value) if isinstance(value, Group) else annotations.get(var_name)
180+
inferred = ModelField.infer(name=var_name, value=value, annotation=annotation,
177181
class_validators=validators.get(var_name, []), config=config)
178182
if var_name in fields and inferred.type_ != fields[var_name].type_:
179183
raise TypeError(f'The type of {name}.{var_name} differs from the new default value; '

0 commit comments

Comments
 (0)