8000 Make all our dataclasses frozen by PerchunPak · Pull Request #743 · py-mine/mcstatus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make all our dataclasses frozen #743

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

Merged
merged 2 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mcstatus/motd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
MOTD_COLORS_RE = re.compile(r"([\xA7|&][0-9A-FK-OR])", re.IGNORECASE)


@dataclass
@dataclass(frozen=True)
class Motd:
"""Represents parsed MOTD."""

Expand Down
4 changes: 2 additions & 2 deletions mcstatus/motd/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class MinecraftColor(Enum):
MINECOIN_GOLD = "g"


@dataclass
@dataclass(frozen=True)
class WebColor:
"""Raw HTML color from MOTD.

Expand Down Expand Up @@ -110,7 +110,7 @@ def _check_rgb(rgb: tuple[int, int, int]) -> None:
raise ValueError(f"RGB color byte out of its 8-bit range (0-255) for {color_name} ({value=})")


@dataclass
@dataclass(frozen=True)
class TranslationTag:
"""Represents a ``translate`` field in server's answer.

Expand Down
20 changes: 10 additions & 10 deletions mcstatus/status_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RawJavaResponse(TypedDict):
]


@dataclass
@dataclass(frozen=True)
class BaseStatusResponse(ABC):
"""Class for storing shared data from a status response."""

Expand Down Expand Up @@ -101,7 +101,7 @@ def build(cls, *args, **kwargs) -> Self:
raise NotImplementedError("You can't use abstract methods.")


@dataclass
@dataclass(frozen=True)
class JavaStatusResponse(BaseStatusResponse):
"""The response object for :meth:`JavaServer.status() <mcstatus.server.JavaServer.status>`."""

Expand Down Expand Up @@ -159,7 +159,7 @@ def build(cls, raw: RawJavaResponse, latency: float = 0) -> Self:
)


@dataclass
@dataclass(frozen=True)
class BedrockStatusResponse(BaseStatusResponse):
"""The response object for :meth:`BedrockServer.status() <mcstatus.server.BedrockServer.status>`."""

Expand Down Expand Up @@ -205,7 +205,7 @@ def build(cls, decoded_data: list[Any], latency: float) -> Self:
)


@dataclass
@dataclass(frozen=True)
class BaseStatusPlayers(ABC):
"""Class for storing information about players on the server."""

Expand All @@ -215,7 +215,7 @@ class BaseStatusPlayers(ABC):
"""The maximum allowed number of players (aka server slots)."""


@dataclass
@dataclass(frozen=True)
class JavaStatusPlayers(BaseStatusPlayers):
"""Class for storing information about players on the server."""

Expand Down Expand Up @@ -252,12 +252,12 @@ def build(cls, raw: RawJavaResponsePlayers) -> Self:
)


@dataclass
@dataclass(frozen=True)
class BedrockStatusPlayers(BaseStatusPlayers):
"""Class for storing information about players on the server."""


@dataclass
@dataclass(frozen=True)
class JavaStatusPlayer:
"""Class with information about a single player."""

Expand All @@ -284,7 +284,7 @@ def build(cls, raw: RawJavaResponsePlayer) -> Self:
return cls(name=raw["name"], id=raw["id"])


@dataclass
@dataclass(frozen=True)
class BaseStatusVersion(ABC):
"""A class for storing version information."""

Expand All @@ -301,7 +301,7 @@ class BaseStatusVersion(ABC):
"""


@dataclass
@dataclass(frozen=True)
class JavaStatusVersion(BaseStatusVersion):
"""A class for storing version information."""

Expand All @@ -318,7 +318,7 @@ def build(cls, raw: RawJavaResponseVersion) -> Self:
return cls(name=raw["name"], protocol=raw["protocol"])


@dataclass
@dataclass(frozen=True)
class BedrockStatusVersion(BaseStatusVersion):
"""A class for storing version information."""

Expand Down
7 changes: 3 additions & 4 deletions tests/status_response/test_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ def build(self) -> JavaStatusPlayer:
return JavaStatusPlayer.build({"name": "foo", "id": "0b3717c4-f45d-47c8-b8e2-3d9ff6f93a89"})

def test_id_field_the_same_as_uuid(self) -> None:
build = Jav 6A8B aStatusPlayer.build({"name": "foo", "id": "0b3717c4-f45d-47c8-b8e2-3d9ff6f93a89"})
unique = object()
build = JavaStatusPlayer.build({"name": "foo", "id": unique}) # type: ignore[assignment]
assert build.id is build.uuid

build.id = unique = object() # type: ignore[assignment]
assert unique is build.uuid
assert build.uuid is unique


@BaseStatusResponseTest.construct
Expand Down
0