Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dataclasses.FrozenInstanceError via .delegates.txt_parser.common #1766

Open
khaeru opened this issue May 2, 2023 · 2 comments
Open

dataclasses.FrozenInstanceError via .delegates.txt_parser.common #1766

khaeru opened this issue May 2, 2023 · 2 comments

Comments

@khaeru
Copy link
Contributor

khaeru commented May 2, 2023

I just ran into a cryptic:

dataclasses.FrozenInstanceError: cannot assign to field '__traceback__'

…using pint 0.21 and dask 2023.4.0 together. The exception is actually thrown from within contextlib:

  File "/home/khaeru/vc/genno/genno/core/computer.py", line 499, in get
    result = dask_get(dsk, key)
             ^^^^^^^^^^^^^^^^^^
   File "/home/khaeru/.venv/3.11/lib/python3.11/site-packages/dask/local.py", line 557, in get_sync
    return get_async(
           ^^^^^^^^^^
   File "/home/khaeru/.venv/3.11/lib/python3.11/site-packages/dask/local.py", line 425, in get_async
    with local_callbacks(callbacks) as callbacks:
   File "/usr/lib/python3.11/contextlib.py", line 189, in __exit__
    exc.__traceback__ = traceback
    ^^^^^^^^^^^^^^^^^
   File "<string>", line 4, in __setattr__

I see that 08b9807 set @dataclass(frozen=False) in several places in pint.errors with the commit message "Using frozen=False in errors to avoid problems with dask". Upon some digging, I discovered the offending class in my case was actually this one:

@dataclass(frozen=True)
class DefinitionSyntaxError(errors.DefinitionSyntaxError, fp.ParsingError):

This appears to have been missed in the earlier commit.

@khaeru
Copy link
Contributor Author

khaeru commented May 2, 2023

Perhaps worth noting that this is filed as a bug in CPython per se: python/cpython#99856

Depending on the resolution, maybe pint could eventually go back to frozen=True if that's desired.

khaeru added a commit to iiasa/ixmp that referenced this issue May 2, 2023
glatterf42 pushed a commit to iiasa/ixmp that referenced this issue May 2, 2023
@hgrecco
Copy link
Owner

hgrecco commented May 2, 2023

I like frozen dataclasses. It makes things easier to reason around. But it seems that exceptions cannot be frozen in dask. I was wonder what would happen if we add a traceback get/set property and use this to change its value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants