hgrecco / pint

Operate and manipulate physical quantities in Python
http://pint.readthedocs.org/
Other
2.41k stars 473 forks source link

pint 0.24.3 - Python 3.11.9 error: cannot inherit frozen dataclass from a non-frozen one #2074

Closed Zippy1999 closed 2 weeks ago

Zippy1999 commented 2 weeks ago

I am seeing the same problem but on python 3.11.9 using pint 0.24.3

<module>
    @dataclass(frozen=True)
../../../../.pyenv/versions/3.11.9/lib/python3.11/dataclasses.py:1222: in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
../../../../.pyenv/versions/3.11.9/lib/python3.11/dataclasses.py:993: in _process_class
    raise TypeError('cannot inherit frozen dataclass from a '
E   TypeError: cannot inherit frozen dataclass from a non-frozen one

Everything was working yesterday but after reinstalling the project's virtual env / deps this morning, I am seeing this error

The file in question throwing the issue is lib/python3.11/site-packages/pint/delegates/txt_defparser/common.py on line 23

@dataclass(frozen=True)
class DefinitionSyntaxError(errors.DefinitionSyntaxError, fp.ParsingError):
LorenzoRinaldi commented 2 weeks ago

same problem here: it works if you downgrade flex parser to 0.3.1

Zippy1999 commented 2 weeks ago

You just beat me to it 👍

Zippy1999 commented 2 weeks ago

Looking at the code there was a change in master to bump flexparser but fix the affected classes

https://github.com/hgrecco/pint/commit/d592aff209a0eeae9383042368906dfb5edc5f54#diff-4d7c51b1efe9043e44439a949dfd92e5827321b34082903477fd04876edb7552

As the current version has 0.31> , we are getting the latest flexparser without the dataclass fixes

stefdoerr commented 2 weeks ago

Also started getting the error suddenly today in python 3.10 and the timing coincides with the release of flexparser 0.4

josteinl commented 2 weeks ago

Need to pin version 0.24.x to flexparser < 0.4.

stefdoerr commented 2 weeks ago

Someone made a conda-forge patch for the current release https://anaconda.org/conda-forge/pint/files It should be fixed now on conda-forge

jasper-tms commented 2 weeks ago

For anyone who wants a copy-paste, this downgrade is what has been suggested above, and works perfectly well for me too:

pip install --upgrade 'flexparser<0.4'
hgrecco commented 2 weeks ago

I apologize for the inconvenience. This change was needed due to a modification in the semantics of frozen dataclass in Python 3.13. It will be fixed with the release today.

hgrecco commented 2 weeks ago

I am closing this issue as is fixed in Pint 0.24.4 Please let me know if you encounter any problem.

Zippy1999 commented 1 week ago

@hgrecco apologies for the late reply - thanks for looking into this 👍 Keep up the excellent work, it is much appreciated.