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

fix: invalid dataclass mutable default #388

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

ds-filipknefel
Copy link
Contributor

Importing TextRegion from unstructured_inference.inference.elements causes the following error

  File "<stdin>", line 1, in <module>
  File "/home/filip/Unstructured/unstructured-inference/unstructured_inference/inference/elements.py", line 209, in <module>
    @dataclass
     ^^^^^^^^^
  File "/home/filip/.pyenv/versions/3.12.1/lib/python3.12/dataclasses.py", line 1266, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/home/filip/.pyenv/versions/3.12.1/lib/python3.12/dataclasses.py", line 1256, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/filip/.pyenv/versions/3.12.1/lib/python3.12/dataclasses.py", line 994, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/filip/.pyenv/versions/3.12.1/lib/python3.12/dataclasses.py", line 852, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'numpy.ndarray'> for field texts is not allowed: use default_factory

this PR modifies the default value to be assigned via default_factory as instructed.

@ds-filipknefel ds-filipknefel merged commit 3071c85 into main Sep 30, 2024
5 checks passed
@ds-filipknefel ds-filipknefel deleted the fix/invalid-dataclass-default branch September 30, 2024 14:14
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

Successfully merging this pull request may close these issues.

2 participants