Search code examples
pythondiscordpython-dataclassespycord

ValueError: mutable default <class 'discord.utils._MissingSentinel'> for field name is not allowed: use default_factory when importing ext.commands


I'm using pycord version 2.1.3, on macOS Monterey

When I try to from discord.ext import commands, I get the following error message:

/Users/montw/dev/gen2/src/bot/ext $ /Users/montw/d
ev/gen2/.venv/bin/python -B /Users/montw/dev/gen2/src/bot/ext/core.p
y
Traceback (most recent call last):
  File "/Users/montw/dev/gen2/src/bot/ext/core.py", line 2, in <module>
    from discord.ext import commands
  File "/Users/montw/dev/gen2/.venv/lib/python3.11/site-packages/discord/ext/commands/__init__.py", line 18, in <module>
    from .flags import *
  File "/Users/montw/dev/gen2/.venv/lib/python3.11/site-packages/discord/ext/commands/flags.py", line 71, in <module>
    @dataclass
     ^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/dataclasses.py", line 1221, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/dataclasses.py", line 1211, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/dataclasses.py", line 959, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/dataclasses.py", line 816, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'discord.utils._MissingSentinel'> for field name is not allowed: use default_factory

The same code was working fine on Windows. Why do I keep getting this error? All answers I found were related to dataclasses but did not help much.


Solution

  • This issue will be fixed on the next update, 2.2.3 or something similar. For now it is possible to use the development version.