Skip to content

Commit

Permalink
@DataClass(frozen=True) for Python 3.13 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jul 13, 2024
1 parent 280b037 commit 4b34753
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pint/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def def_err(self, msg: str):
return DefinitionError(self.name, self.__class__, msg)


@dataclass(frozen=False)
@dataclass(frozen=True)
class PintError(Exception):
"""Base exception for all Pint errors."""


@dataclass(frozen=False)
@dataclass(frozen=True)
class DefinitionError(ValueError, PintError):
"""Raised when a definition is not properly constructed."""

Expand All @@ -102,7 +102,7 @@ def __reduce__(self):
return self.__class__, tuple(getattr(self, f.name) for f in fields(self))


@dataclass(frozen=False)
@dataclass(frozen=True)
class DefinitionSyntaxError(ValueError, PintError):
"""Raised when a textual definition has a syntax error."""

Expand All @@ -115,7 +115,7 @@ def __reduce__(self):
return self.__class__, tuple(getattr(self, f.name) for f in fields(self))


@dataclass(frozen=False)
@dataclass(frozen=True)
class RedefinitionError(ValueError, PintError):
"""Raised when a unit or prefix is redefined."""

Expand All @@ -130,7 +130,7 @@ def __reduce__(self):
return self.__class__, tuple(getattr(self, f.name) for f in fields(self))


@dataclass(frozen=False)
@dataclass(frozen=True)
class UndefinedUnitError(AttributeError, PintError):
"""Raised when the units are not defined in the unit registry."""

Expand All @@ -150,13 +150,13 @@ def __reduce__(self):
return self.__class__, tuple(getattr(self, f.name) for f in fields(self))


@dataclass(frozen=False)
@dataclass(frozen=True)
class PintTypeError(TypeError, PintError):
def __reduce__(self):
return self.__class__, tuple(getattr(self, f.name) for f in fields(self))


@dataclass(frozen=False)
@dataclass(frozen=True)
class DimensionalityError(PintTypeError):
"""Raised when trying to convert between incompatible units."""

Expand All @@ -183,7 +183,7 @@ def __reduce__(self):
return self.__class__, tuple(getattr(self, f.name) for f in fields(self))


@dataclass(frozen=False)
@dataclass(frozen=True)
class OffsetUnitCalculusError(PintTypeError):
"""Raised on ambiguous operations with offset units."""

Expand All @@ -208,7 +208,7 @@ def __reduce__(self):
return self.__class__, tuple(getattr(self, f.name) for f in fields(self))


@dataclass(frozen=False)
@dataclass(frozen=True)
class LogarithmicUnitCalculusError(PintTypeError):
"""Raised on inappropriate operations with logarithmic units."""

Expand All @@ -233,21 +233,21 @@ def __reduce__(self):
return self.__class__, tuple(getattr(self, f.name) for f in fields(self))


@dataclass(frozen=False)
@dataclass(frozen=True)
class UnitStrippedWarning(UserWarning, PintError):
msg: str

def __reduce__(self):
return self.__class__, tuple(getattr(self, f.name) for f in fields(self))


@dataclass(frozen=False)
@dataclass(frozen=True)
class UnexpectedScaleInContainer(Exception):
def __reduce__(self):
return self.__class__, tuple(getattr(self, f.name) for f in fields(self))


@dataclass(frozen=False)
@dataclass(frozen=True)
class UndefinedBehavior(UserWarning, PintError):
msg: str

Expand Down

0 comments on commit 4b34753

Please sign in to comment.