Skip to content

Commit

Permalink
Remove use of slots in dataclasses (#44)
Browse files Browse the repository at this point in the history
Support for slots in dataclasses was added in 3.10. The workaround we had
wasn’t working correctly with the type checker.
  • Loading branch information
samdoran authored Nov 20, 2024
1 parent 81689b5 commit 71439ed
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions command_line_assistant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,7 @@
"""


def dataclass(cls, slots=True):
"""Custom dataclass decorator to mimic the behavior of dataclass for Python 3.9"""
try:
return dataclasses.dataclass(cls, slots=slots)
except TypeError:

def wrap(cls):
# Create a new dict for our new class.
cls_dict = dict(cls.__dict__)
field_names = tuple(name for name in cls_dict.keys())
# The slots for our class
cls_dict["__slots__"] = field_names
return dataclasses.dataclass(cls)

return wrap(cls)


@dataclass
@dataclasses.dataclass
class LoggingSchema:
"""This class represents the [logging] section of our config.toml file."""

Expand All @@ -79,7 +62,7 @@ def __post_init__(self):
self.file = Path(self.file).expanduser()


@dataclass
@dataclasses.dataclass
class OutputSchema:
"""This class represents the [output] section of our config.toml file."""

Expand All @@ -91,7 +74,7 @@ def __post_init__(self):
self.file = Path(self.file).expanduser()


@dataclass
@dataclasses.dataclass
class HistorySchema:
"""This class represents the [history] section of our config.toml file."""

Expand All @@ -105,15 +88,15 @@ def __post_init__(self):
self.file = Path(self.file).expanduser()


@dataclass
@dataclasses.dataclass
class BackendSchema:
"""This class represents the [backend] section of our config.toml file."""

endpoint: str = "http://0.0.0.0:8080/v1/query"
verify_ssl: bool = True


@dataclass
@dataclasses.dataclass
class Config:
"""Class that holds our configuration file representation.
Expand Down

0 comments on commit 71439ed

Please sign in to comment.