jeffwright13 / pytest-tui

A Text User Interface (TUI) for Pytest, with console scripts to launch a TUI or an HTML page
MIT License
31 stars 1 forks source link

pytest-tui craps out when running with Python 3.11 #84

Open jeffwright13 opened 1 year ago

jeffwright13 commented 1 year ago
...
  File "/Users/jwr003/coding/pytest-html-dev/venv/lib/python3.11/site-packages/pytest_tui/utils.py", line 181, in <module>
    @dataclass
     ^^^^^^^^^
  File "/Users/jwr003/.pyenv/versions/3.11.1/lib/python3.11/dataclasses.py", line 1220, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/Users/jwr003/.pyenv/versions/3.11.1/lib/python3.11/dataclasses.py", line 1210, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jwr003/.pyenv/versions/3.11.1/lib/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jwr003/.pyenv/versions/3.11.1/lib/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'pytest_tui.utils.TuiSection'> for field live_log_sessionstart is not allowed: use default_factory

According to https://github.com/huggingface/datasets/issues/5230, this is due to Python 3.11 making changes in the dataclasses library:

https://docs.python.org/3/library/dataclasses.html

Changed in version 3.11: Instead of looking for and disallowing objects of type list, dict, or set, unhashable objects are now not allowed as default values. Unhashability is used to approximate mutability.

fields may optionally specify a default value, using normal Python syntax:

@dataclass class C: a: int # 'a' has no default value b: int = 0 # assign a default value for 'b' In this example, both a and b will be included in the added init() method, which will be defined as:

def init(self, a: int, b: int = 0): Changed in version 3.11: If a field name is already included in the slots of a base class, it will not be included in the generated slots to prevent overriding them. Therefore, do not use slots to retrieve the field names of a dataclass. Use fields() instead. To be able to determine inherited slots, base class slots may be any iterable, but not an iterator.

weakref_slot: If true (the default is False), add a slot named “weakref”, which is required to make an instance weakref-able. It is an error to specify weakref_slot=True without also specifying slots=True. TypeError will be raised if a field without a default value follows a field with a default value. This is true whether this occurs in a single class, or as a result of class inheritance.

jeffwright13 commented 1 year ago

It's not just 3.11, it's 3.10 as well. In the meantime I've removed support for >3.9 as of 1.9. Will figure this out later.