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
importdataclassesimportdataclass_utils@dataclasses.dataclassclassFooWithSugar:
bar: str|int="bar"f_sugar=FooWithSugar()
dataclass_utils.check_type(f_sugar)
print(f"Pass! {f_sugar=}")
Fails with:
/home/agimg/anaconda3/envs/pbrl/bin/python /home/agimg/projects/fastpbrl/scripts/scratchpads/dataclass_utils_bug_2.py
Traceback (most recent call last):
File "/home/agimg/projects/fastpbrl/scripts/scratchpads/dataclass_utils_bug_2.py", line 25, in
dataclass_utils.check_type(f_sugar)
File "/home/agimg/anaconda3/envs/pbrl/lib/python3.10/site-packages/dataclass_utils/type_checker.py", line 189, in check_root
raise err
dataclass_utils.error.Error0: Error in field 'bar'. Expected type <class 'types.UnionType'>, got <class 'str'> (value: bar)
Process finished with exit code 1
Do you plan on supporting this new syntax?
The text was updated successfully, but these errors were encountered:
Hi there, I ran into another bug while using this:
I'm using python 3.10 which has some syntax sugar for creating unions using the | operator from https://peps.python.org/pep-0604/
Interestingly, this causes the type checking to fail, when using the old way of creating a
typing.Union
object doesn't:Here's the base case:
This passes as expected:
But using the syntax sugar:
Fails with:
Do you plan on supporting this new syntax?
The text was updated successfully, but these errors were encountered: