4 ms·
Data classes do not do runtime type checking. They are a way for static type checkers to do validation. So there’s no issue for data classes in 3.10.
by Mehdi2277 6y ago
Data classes do not do runtime type checking. They are a way for static type checkers to do validation. So there’s no issue for data classes in 3.10.
- nemetroid 6y agoData classes don't do runtime type checking, but they do provide dynamic type info through dataclasses.fields(). This function returns a tuple of Field objects, and according to the documentation[1], Field includes the attribute "type": type: The type of the field. In Python 3.10, this now returns a string. In my opinion that's a bug (perhaps in the docs). I verified this using a short test program: import dataclasses @dataclasses.dataclass class Apa: bepa: int first_field = dataclasses.fields(Apa)[0] print(type(first_field.type)) Running with 3.9 and 3.10: $ python test.py # Python 3.9 <class 'type'> $ python3.10 test.py <class 'str'> 1: https://docs.python.org/3.10/library/dataclasses.html#dataclasses.Field https://docs.python.org/3.10/library/dataclasses.html#datacl...
- nerdponx 6y agoThat is indeed annoying. Thanks for the example.
- travisjungroth 6y agoThe variable annotations are used at runtime to define the fields. They aren't type checked.