Skip to content
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
10 changes: 5 additions & 5 deletions mcstatus/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Address(_AddressBase):
The class is not a part of a Public API, but attributes :attr:`host` and :attr:`port` are a part of Public API.
"""

def __init__(self, host: str, port: int): # noqa: ARG002 # unused arguments
def __init__(self, host: str, port: int) -> None: # noqa: ARG002 # unused arguments
# We don't pass the host & port args to super's __init__, because NamedTuples handle
# everything from __new__ and the passed self already has all of the parameters set.
super().__init__()
Expand Down Expand Up @@ -219,12 +219,12 @@ def minecraft_srv_address_lookup(
# to the default_port (if it's defined).
try:
host, port = mcstatus.dns.resolve_mc_srv(host, lifetime=lifetime)
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer) as e:
if default_port is None:
raise ValueError(
f"Given address '{address}' doesn't contain port, doesn't have an SRV record pointing to a port,"
" and default_port wasn't specified, can't parse."
)
) from e
port = default_port

return Address(host, port)
Expand All @@ -248,12 +248,12 @@ async def async_minecraft_srv_address_lookup(
# to the default_port (if it's defined).
try:
host, port = await mcstatus.dns.async_resolve_mc_srv(host, lifetime=lifetime)
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer):
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer) as e:
if default_port is None:
raise ValueError(
f"Given address '{address}' doesn't contain port, doesn't have an SRV record pointing to a port,"
" and default_port wasn't specified, can't parse."
)
) from e
port = default_port

return Address(host, port)
2 changes: 1 addition & 1 deletion mcstatus/bedrock_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BedrockServerStatus:
"01" + "0000000000000000" + "00ffff00fefefefefdfdfdfd12345678" + "0000000000000000"
)

def __init__(self, address: Address, timeout: float = 3):
def __init__(self, address: Address, timeout: float = 3) -> None:
self.address = address
self.timeout = timeout

Expand Down
4 changes: 2 additions & 2 deletions mcstatus/legacy_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parse_response(data: bytes, latency: float) -> LegacyStatusResponse:


class LegacyServerStatus(_BaseLegacyServerStatus):
def __init__(self, connection: BaseSyncConnection):
def __init__(self, connection: BaseSyncConnection) -> None:
self.connection = connection

def read_status(self) -> LegacyStatusResponse:
Expand All @@ -37,7 +37,7 @@ def read_status(self) -> LegacyStatusResponse:


class AsyncLegacyServerStatus(_BaseLegacyServerStatus):
def __init__(self, connection: BaseAsyncReadSyncWriteConnection):
def __init__(self, connection: BaseAsyncReadSyncWriteConnection) -> None:
self.connection = connection

async def read_status(self) -> LegacyStatusResponse:
Expand Down
4 changes: 2 additions & 2 deletions mcstatus/motd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ def _parse_color(color: str) -> ParsedMotdComponent:
# achieve gradients.
try:
return WebColor.from_hex(color)
except ValueError:
raise ValueError(f"Unable to parse color: {color!r}, report this!")
except ValueError as e:
raise ValueError(f"Unable to parse color: {color!r}, report this!") from e

def simplify(self) -> Self:
"""Create new MOTD without unused elements.
Expand Down
4 changes: 2 additions & 2 deletions mcstatus/motd/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def from_hex(cls, hex: str) -> Self: # noqa: A002 # shadowing a hex builtin

try:
rgb = t.cast("tuple[int, int, int]", tuple(int(hex[i : i + 2], 16) for i in (0, 2, 4)))
except ValueError:
raise ValueError(f"Failed to parse given hex color: {'#' + hex!r}")
except ValueError as e:
raise ValueError(f"Failed to parse given hex color: {'#' + hex!r}") from e

return cls.from_rgb(rgb)

Expand Down
6 changes: 3 additions & 3 deletions mcstatus/pinger.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def _handle_status_response(self, response: Connection, start: float, end: float
raise OSError("Received invalid status response packet.")
try:
raw: RawJavaResponse = json.loads(response.read_utf())
except ValueError:
raise OSError("Received invalid JSON")
except ValueError as e:
raise OSError("Received invalid JSON") from e

try:
latency_ms = (end - start) * 1000
return JavaStatusResponse.build(raw, latency=latency_ms)
except KeyError as e:
raise OSError(f"Received invalid status response: {e!r}")
raise OSError("Received invalid status response") from e

def _handle_ping_response(self, response: Connection, start: float, end: float) -> float:
"""Given a ping response buffer, validate token and compute latency."""
Expand Down
4 changes: 2 additions & 2 deletions mcstatus/protocol/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class TCPSocketConnection(SocketConnection):

__slots__ = ()

def __init__(self, addr: tuple[str | None, int], timeout: float = 3):
def __init__(self, addr: tuple[str | None, int], timeout: float = 3) -> None:
super().__init__()
self.socket = socket.create_connection(addr, timeout=timeout)
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
Expand Down Expand Up @@ -562,7 +562,7 @@ class UDPSocketConnection(SocketConnection):

__slots__ = ("addr",)

def __init__(self, addr: Address, timeout: float = 3):
def __init__(self, addr: Address, timeout: float = 3) -> None:
super().__init__()
self.addr = addr
self.socket = socket.socket(
Expand Down
4 changes: 2 additions & 2 deletions mcstatus/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MCServer(ABC):

DEFAULT_PORT: int

def __init__(self, host: str, port: int | None = None, timeout: float = 3):
def __init__(self, host: str, port: int | None = None, timeout: float = 3) -> None:
"""
:param host: The host/ip of the minecraft server.
:param port: The port that the server is on.
Expand Down Expand Up @@ -92,7 +92,7 @@ async def async_lookup(cls, address: str, timeout: float = 3) -> Self:
class JavaServer(BaseJavaServer):
"""Base class for a 1.7+ Minecraft Java Edition server."""

def __init__(self, host: str, port: int | None = None, timeout: float = 3, query_port: int | None = None):
def __init__(self, host: str, port: int | None = None, timeout: float = 3, query_port: int | None = None) -> None:
"""
:param host: The host/ip of the minecraft server.
:param port: The port that the server is on.
Expand Down
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ select = ["ALL"]
ignore = [
"EM", # Very weird rules for using exceptions
"FIX", # Line contains TODO, consider resolving the issue
"ANN204", # Missing return type annotation for special method
"B904", # Exception raised within try-except should use raise ... from exc
"COM812", # Missing trailing comma (in multiline lists/tuples/...)
"D203", # Blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
Expand Down Expand Up @@ -189,9 +187,6 @@ lines-after-imports = -1 # The number of blank lines to place after impor
lines-between-types = 0 # Number of lines to place between "direct" and import from imports
split-on-trailing-comma = false # if last member of multiline import has a comma, don't fold it to single line

[tool.ruff.lint.flake8-implicit-str-concat]
allow-multiline = false

[tool.ruff.lint.flake8-annotations]
allow-star-arg-any = true

Expand All @@ -201,7 +196,7 @@ max-args = 10
[tool.ruff.lint.flake8-builtins]
ignorelist = ["id", "copyright"]

[tool.ruff-formatter]
[tool.ruff.format]
line-ending = "lf"

[project.scripts]
Expand Down