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

Use default factories for dataclass attributes #20

Merged
merged 1 commit into from
Sep 17, 2024

Conversation

fhchl
Copy link

@fhchl fhchl commented Sep 17, 2024

For Python > 3.11 dataclass field initial values are checked for mutability so we get a type error

tests/test_templates.py:3: in <module>
    import prompts
prompts/__init__.py:1: in <module>
    from .templates import template
prompts/templates.py:10: in <module>
    from prompts.tokens import SPECIAL_TOKENS, Special
prompts/tokens.py:11: in <module>
    @dataclass
../../.pyenv/versions/3.11.9/lib/python3.11/dataclasses.py:1232: in dataclass
    return wrap(cls)
../../.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:958: in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
../../.pyenv/versions/3.11.9/lib/python3.11/dataclasses.py:815: in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
E   ValueError: mutable default <class 'prompts.tokens.Limits'> for field sequence is not allowed: use default_factory

This PR just adds those default factories.

@rlouf rlouf merged commit 2464eca into dottxt-ai:master Sep 17, 2024
5 checks passed
@rlouf
Copy link
Member

rlouf commented Sep 17, 2024

Thank you!

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