You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# TODO: Revisit test_name_qualname_reuse_typevar_known_issue with pydantic v2. Expected to change
assertMyModel(a=1) !=MyInherited(a=1)
deftest_name_qualname_and_module() ->None:
assertModel.__name__=='Model'assertModel.__qualname__=='Model'assertModel.__module__=='omnipy.data.model'assertModel[int].__name__=='Model[int]'assertModel[int].__qualname__=='Model[int]'assertModel[int].__module__=='omnipy.data.model'assertModel[Model[None]].__name__=='Model[Model[None]]'assertModel[Model[None]].__qualname__=='Model[Model[None]]'assertModel[Model[None]].__module__=='omnipy.data.model'assertModel[dict[str, Model[None]]].__name__=='Model[dict[str, Model[None]]]'assertModel[dict[str, Model[None]]].__qualname__=='Model[dict[str, Model[None]]]'assertModel[dict[str, Model[None]]].__module__=='omnipy.data.model'assertModel[list[T]][int].__name__=='Model[list[~T]][int]'assertModel[list[T]][int].__qualname__=='Model[list[~T]][int]'assertModel[list[T]][int].__module__=='omnipy.data.model'ABC_PREFIX='test_name_qualname_and_module.<locals>.ABC.'DEF_PREFIX='test_name_qualname_and_module.<locals>.DEF.'classABC:
classMyModel(Model[list[T]], Generic[T]):
...
assertMyModel.__name__=='MyModel'assertMyModel.__qualname__==ABC_PREFIX+'MyModel'assertMyModel[int].__name__=='MyModel[int]'assertMyModel[int].__qualname__==ABC_PREFIX+'MyModel[int]'assertMyModel[U].__name__=='MyModel[~U]'assertMyModel[U].__qualname__==ABC_PREFIX+'MyModel[~U]'assertMyModel.__module__=='tests.data.test_model'classDEF:
classMyTupleModel(ABC.MyModel[tuple[T, U]], Generic[T, U]):
...
assertMyTupleModel.__name__=='MyTupleModel'assertMyTupleModel.__qualname__==DEF_PREFIX+'MyTupleModel'assertMyTupleModel[int, str].__name__=='MyTupleModel[int, str]'assertMyTupleModel[int, str].__qualname__==DEF_PREFIX+'MyTupleModel[int, str]'assertMyTupleModel.__module__=='tests.data.test_model'assertABC.MyModel[int].__name__=='MyModel[int]'assertABC.MyModel[int].__qualname__==ABC_PREFIX+'MyModel[int]'assertABC.MyModel[ABC.MyModel[int]].__name__=='MyModel[MyModel[int]]'assertABC.MyModel[ABC.MyModel[int]].__qualname__==ABC_PREFIX+'MyModel[MyModel[int]]'assertABC.MyModel[Union[str, ABC.MyModel[str|int]]].__name__== \
'MyModel[str | MyModel[str | int]]'assertABC.MyModel[Union[str, ABC.MyModel[str|int]]].__qualname__== \
ABC_PREFIX+'MyModel[str | MyModel[str | int]]'assertABC.MyModel[ABC.MyModel[Union[str, int]] |str].__name__== \
'MyModel[MyModel[str | int] | str]'assertABC.MyModel[ABC.MyModel[str|int] |str].__qualname__== \
ABC_PREFIX+'MyModel[MyModel[str | int] | str]'assertDEF.MyTupleModel[int, str].__name__=='MyTupleModel[int, str]'assertDEF.MyTupleModel[int, str].__qualname__==DEF_PREFIX+'MyTupleModel[int, str]'assertDEF.MyTupleModel[int, ABC.MyModel[str]].__name__== \
'MyTupleModel[int, MyModel[str]]'assertDEF.MyTupleModel[int, ABC.MyModel[str]].__qualname__== \
(DEF_PREFIX+'MyTupleModel[int, MyModel[str]]')
assertMyFwdRefModel.__name__=='MyGenericModel[NumberModel]'assertMyFwdRefModel.__qualname__=='CBA.MyGenericModel[NumberModel]'assertMyFwdRefModel.__module__=='tests.data.helpers.models'assertMyNestedFwdRefModel.__name__=='MyGenericModel[str | NumberModel]'assertMyNestedFwdRefModel.__qualname__=='CBA.MyGenericModel[str | NumberModel]'assertMyNestedFwdRefModel.__module__=='tests.data.helpers.models'assert (CBA.MyGenericModel[ForwardRef('ABC.MyModel[int]')].__name__==# noqa: W504'MyGenericModel[ABC.MyModel[int]]')
assert (CBA.MyGenericModel[ForwardRef('ABC.MyModel[int]')].__qualname__==# noqa: W504'CBA.MyGenericModel[ABC.MyModel[int]]')
assert (CBA.MyGenericModel[ForwardRef('ABC.MyModel[int]')].__module__==# noqa: W504'tests.data.helpers.models')
assert (CBA.MyGenericModel['Union[str, ABC.MyModel[int]]'].__name__==# noqa: W504'MyGenericModel[Union[str, ABC.MyModel[int]]]')
assert (CBA.MyGenericModel['Union[str, ABC.MyModel[int]]'].__qualname__==# noqa: W504'CBA.MyGenericModel[Union[str, ABC.MyModel[int]]]')
assert (CBA.MyGenericModel['Union[str, ABC.MyModel[int]]'].__module__==# noqa: W504'tests.data.helpers.models')
# TODO: Revisit test_name_qualname_reuse_typevar_known_issue with pydantic v2. Expected to change@pytest.mark.skipif(os.getenv('OMNIPY_FORCE_SKIPPED_TEST') !='1',reason="""Known issue due to bug in pydantic v1 where a generic model defined with some TypeVar(s)parametrized with the exact same TypeVar(s) are assumed to be the same model: https://github.com/pydantic/pydantic/blob/5ebcdc13b83fba5da34ad9b0f008f7b4faf89396/pydantic/generics.py#L110This causes issues if generic models inherit from each other while having the same TypeVar(s).TypeVar(s) in Python are bound only within the scope of a class or function, so the same TypeVar(s)in different classes should not be assumed to be the same.For now, the only consequence of the bug that we are aware of is that the `__name__` and`__qualname__` of the models are slightly incorrect and will not print the TypeVars. However,worse consequences might be hidden in the code.""")deftest_name_qualname_reuse_typevar_known_issue() ->None:
classMyModel(Model[T], Generic[T]):
...
assertMyModel[T].__name__=='MyModel[~T]'assertMyModel[T].__qualname__=='MyModel[~T]'deftest_repr() ->None:
The text was updated successfully, but these errors were encountered:
omnipy/tests/data/test_model.py
Line 484 in 86e1ee9
The text was updated successfully, but these errors were encountered: