Skip to content

fix: support for python3.11 dataclass mutability https://github.com/p… #4

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brvier
Copy link

@brvier brvier commented Sep 12, 2023

In python 3.11

https://www.micahsmith.com/blog/2020/01/dataclasses-mutable-defaults/
python/cpython#88840

➜  py-async-http-logging git:(Py3.11) ✗ python3 tests/unit/test_handler.py
Traceback (most recent call last):
  File "/home/brvier/Projects/py-async-http-logging/tests/unit/test_handler.py", line 3, in <module>
    import http_logging
  File "/home/brvier/.local/lib/python3.11/site-packages/http_logging/__init__.py", line 1, in <module>
    from .secondary_classes import (
  File "/home/brvier/.local/lib/python3.11/site-packages/http_logging/secondary_classes.py", line 47, in <module>
    @dataclass
     ^^^^^^^^^
  File "/usr/lib/python3.11/dataclasses.py", line 1220, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/usr/lib/python3.11/dataclasses.py", line 1210, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'http_logging.secondary_classes.HttpSecurity'> for field security is not allowed: use default_factory

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.

1 participant