Skip to content
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

Bump pyright from 1.1.326 to 1.1.360 #264

Merged
merged 2 commits into from
Apr 29, 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 docs/extensions/attributetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PyAttributeTable(SphinxDirective):
required_arguments = 1
optional_arguments = 0
final_argument_whitespace = False
option_spec: OptionSpec = {} # noqa: RUF012 # (from original impl)
option_spec: OptionSpec = {} # type: ignore # noqa: RUF012 # (from original impl)

def parse_name(self, content: str) -> tuple[str, str]:
match = _name_parser_regex.match(content)
Expand Down
3 changes: 1 addition & 2 deletions mcproto/auth/microsoft/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import TypedDict

import httpx
from typing_extensions import Self

__all__ = [
"MicrosoftOauthResponseErrorType",
Expand Down Expand Up @@ -34,7 +33,7 @@ class MicrosoftOauthResponseErrorType(str, Enum):
UNKNOWN = "This is an unknown error"

@classmethod
def from_status_error(cls, error: str) -> Self:
def from_status_error(cls, error: str) -> MicrosoftOauthResponseErrorType:
"""Determine the error kind based on the error data."""
if error == "expired_token":
return cls.EXPIRED_TOKEN
Expand Down
3 changes: 1 addition & 2 deletions mcproto/auth/microsoft/xbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import NamedTuple

import httpx
from typing_extensions import Self

__all__ = [
"XSTSErrorType",
Expand Down Expand Up @@ -34,7 +33,7 @@ class XSTSErrorType(str, Enum):
UNKNOWN = "This is an unknown error."

@classmethod
def from_status_error(cls, xerr_no: int) -> Self:
def from_status_error(cls, xerr_no: int) -> XSTSErrorType:
"""Determine the error kind based on the error data."""
if xerr_no == 2148916233:
return cls.NO_XBOX_ACCOUNT
Expand Down
2 changes: 1 addition & 1 deletion mcproto/auth/msa.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ServicesAPIErrorType(str, Enum):
UNKNOWN = "This is an unknown error."

@classmethod
def from_status_error(cls, code: int, err_msg: str | None) -> Self:
def from_status_error(cls, code: int, err_msg: str | None) -> ServicesAPIErrorType:
"""Determine the error kind based on the error data."""
if code == 401 and err_msg == "Invalid app registration, see https://aka.ms/AppRegInfo for more information":
return cls.INVALID_REGISTRATION
Expand Down
8 changes: 7 additions & 1 deletion mcproto/auth/yggdrasil.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ class AuthServerApiErrorType(str, Enum):
UNKNOWN = "This is an unknown error."

@classmethod
def from_status_error(cls, code: int, short_msg: str, full_msg: str, cause_msg: str | None) -> Self:
def from_status_error(
cls,
code: int,
short_msg: str,
full_msg: str,
cause_msg: str | None,
) -> AuthServerApiErrorType:
"""Determine the error kind based on the error data."""
if code == 410:
return cls.MICROSOFT_MIGRATED
Expand Down
3 changes: 1 addition & 2 deletions mcproto/multiplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import httpx
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
from typing_extensions import Self

from mcproto.auth.account import Account

Expand All @@ -33,7 +32,7 @@ class UserJoinRequestErrorKind(str, Enum):
UNKNOWN = "This is an unknown error."

@classmethod
def from_status_error(cls, code: int, err_msg: str | None) -> Self:
def from_status_error(cls, code: int, err_msg: str | None) -> UserJoinRequestErrorKind:
"""Determine the error kind based on the status code and error message."""
if code == 403:
if err_msg == "InsufficientPrivilegesException":
Expand Down
2 changes: 1 addition & 1 deletion mcproto/types/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def as_dict(self) -> RawChatMessageDict:
# pragma: no cover
raise TypeError(f"Found unexpected type ({self.raw.__class__!r}) ({self.raw!r}) in `raw` attribute")

def __eq__(self, other: Self) -> bool:
def __eq__(self, other: object) -> bool:
"""Check equality between two chat messages.

..warning: This is purely using the `raw` field, which means it's possible that
Expand Down
15 changes: 9 additions & 6 deletions mcproto/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ def deprecation_warn(
if isinstance(removal_version, str):
removal_version = Version(removal_version)

try:
_project_version = importlib.metadata.version(__package__)
except importlib.metadata.PackageNotFoundError:
# v0.0.0 will never mark things as already deprecated (removal_version will always be newer)
project_version = Version(major=0, minor=0, patch=0)
if isinstance(__package__, str):
try:
_project_version = importlib.metadata.version(__package__)
except importlib.metadata.PackageNotFoundError:
# v0.0.0 will never mark things as already deprecated (removal_version will always be newer)
project_version = Version(major=0, minor=0, patch=0)
else:
project_version = Version(_project_version)
else:
project_version = Version(_project_version)
project_version = Version(major=0, minor=0, patch=0)

already_deprecated = project_version >= removal_version

Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 14 additions & 15 deletions tests/mcproto/protocol/test_base_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import platform
import struct
from abc import ABC, abstractmethod
from typing import Any
from typing import Any, Generic, TypeVar, Union
from unittest.mock import AsyncMock, Mock

import pytest
Expand Down Expand Up @@ -155,11 +155,14 @@ def __init__(self):
# endregion
# region: Abstract test classes

T_WRITER = TypeVar("T_WRITER", bound=Union[BaseSyncWriter, BaseAsyncWriter])
T_READER = TypeVar("T_READER", bound=Union[BaseSyncReader, BaseAsyncReader])

class WriterTests(ABC):

class WriterTests(ABC, Generic[T_WRITER]):
"""Collection of tests for both sync and async versions of the writer."""

writer: BaseSyncWriter | BaseAsyncWriter
writer: T_WRITER

@classmethod
@abstractmethod
Expand Down Expand Up @@ -364,10 +367,10 @@ def test_write_optional_false(self, method_mock: Mock | AsyncMock, write_mock: W
write_mock.assert_has_data(bytearray([0]))


class ReaderTests(ABC):
class ReaderTests(ABC, Generic[T_READER]):
"""Collection of tests for both sync and async versions of the reader."""

reader: BaseSyncReader | BaseAsyncReader
reader: T_READER

@classmethod
@abstractmethod
Expand Down Expand Up @@ -570,7 +573,7 @@ def test_read_optional_false(self, method_mock: Mock | AsyncMock, read_mock: Rea
# region: Concrete test classes


class TestBaseSyncWriter(WriterTests):
class TestBaseSyncWriter(WriterTests[SyncWriter]):
"""Tests for individual write methods implemented in :class:`~mcproto.protocol.base_io.BaseSyncWriter`."""

@classmethod
Expand All @@ -579,7 +582,7 @@ def setup_class(cls):
cls.writer = SyncWriter()


class TestBaseSyncReader(ReaderTests):
class TestBaseSyncReader(ReaderTests[SyncReader]):
"""Tests for individual write methods implemented in :class:`~mcproto.protocol.base_io.BaseSyncReader`."""

@classmethod
Expand All @@ -588,26 +591,22 @@ def setup_class(cls):
cls.reader = SyncReader()


class TestBaseAsyncWriter(WriterTests):
class TestBaseAsyncWriter(WriterTests[AsyncWriter]):
"""Tests for individual write methods implemented in :class:`~mcproto.protocol.base_io.BaseSyncReader`."""

writer: WrappedAsyncWriter

@classmethod
def setup_class(cls):
"""Initialize writer instance to be tested."""
cls.writer = WrappedAsyncWriter()
cls.writer = WrappedAsyncWriter() # type: ignore


class TestBaseAsyncReader(ReaderTests):
class TestBaseAsyncReader(ReaderTests[AsyncReader]):
"""Tests for individual write methods implemented in :class:`~mcproto.protocol.base_io.BaseSyncReader`."""

reader: WrappedAsyncReader

@classmethod
def setup_class(cls):
"""Initialize writer instance to be tested."""
cls.reader = WrappedAsyncReader()
cls.reader = WrappedAsyncReader() # type: ignore


# endregion
Loading