Skip to content

Commit

Permalink
update ruff to v0.5.0 & enable more rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsDrike committed Jun 28, 2024
1 parent cbff05d commit 3374434
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 99 deletions.
1 change: 1 addition & 0 deletions changes/323.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enable various other ruff rules as a part of switching to blacklist model, where we explicitly disable the rules we don't want, rather than enabling dozens of rule groups individually.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from __future__ import annotations

import sys
import datetime
import sys
from pathlib import Path

from packaging.version import parse as parse_version
Expand Down
4 changes: 2 additions & 2 deletions mcproto/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def enable_encryption(self, shared_secret: bytes) -> None:
# subclass. This is needed since the cryptography library calls some C
# code in the back, which relies on this being bytes. If it's not a bytes
# instance, convert it.
if type(shared_secret) is not bytes: # noqa: E721 # we don't want isinstance
if type(shared_secret) is not bytes:
shared_secret = bytes(shared_secret)

self.encryption_enabled = True
Expand Down Expand Up @@ -171,7 +171,7 @@ def enable_encryption(self, shared_secret: bytes) -> None:
# subclass. This is needed since the cryptography library calls some C
# code in the back, which relies on this being bytes. If it's not a bytes
# instance, convert it.
if type(shared_secret) is not bytes: # noqa: E721 # we don't want isinstance
if type(shared_secret) is not bytes:
shared_secret = bytes(shared_secret)

self.encryption_enabled = True
Expand Down
8 changes: 4 additions & 4 deletions mcproto/encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def encrypt_token_and_secret(
# of the bytes class, not any subclass. This is needed since the cryptography
# library calls some C code in the back, which relies on this being bytes. If
# it's not a bytes instance, convert it.
if type(verification_token) is not bytes: # noqa: E721 # we don't want isinstance
if type(verification_token) is not bytes:
verification_token = bytes(verification_token)
if type(shared_secret) is not bytes: # noqa: E721 # we don't want isinstance
if type(shared_secret) is not bytes:
shared_secret = bytes(shared_secret)

encrypted_token = public_key.encrypt(verification_token, PKCS1v15())
Expand All @@ -89,9 +89,9 @@ def decrypt_token_and_secret(
# of the bytes class, not any subclass. This is needed since the cryptography
# library calls some C code in the back, which relies on this being bytes. If
# it's not a bytes instance, convert it.
if type(verification_token) is not bytes: # noqa: E721 # we don't want isinstance
if type(verification_token) is not bytes: # we don't want isinstance
verification_token = bytes(verification_token)
if type(shared_secret) is not bytes: # noqa: E721 # we don't want isinstance
if type(shared_secret) is not bytes: # we don't want isinstance
shared_secret = bytes(shared_secret)

decrypted_token = private_key.decrypt(verification_token, PKCS1v15())
Expand Down
2 changes: 1 addition & 1 deletion mcproto/packets/handshaking/handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from enum import IntEnum
from typing import ClassVar, cast, final

from attrs import define
from typing_extensions import Self, override

from mcproto.buffer import Buffer
from mcproto.packets.packet import GameState, ServerBoundPacket
from mcproto.protocol.base_io import StructFormat
from attrs import define

__all__ = [
"NextState",
Expand Down
2 changes: 1 addition & 1 deletion mcproto/packets/login/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import ClassVar, cast, final

from attrs import define
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat, load_der_public_key
Expand All @@ -11,7 +12,6 @@
from mcproto.packets.packet import ClientBoundPacket, GameState, ServerBoundPacket
from mcproto.types.chat import ChatMessage
from mcproto.types.uuid import UUID
from attrs import define

__all__ = [
"LoginDisconnect",
Expand Down
2 changes: 1 addition & 1 deletion mcproto/packets/status/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from typing import ClassVar, final

from attrs import define
from typing_extensions import Self, override

from mcproto.buffer import Buffer
from mcproto.packets.packet import ClientBoundPacket, GameState, ServerBoundPacket
from mcproto.protocol.base_io import StructFormat
from attrs import define

__all__ = ["PingPong"]

Expand Down
2 changes: 1 addition & 1 deletion mcproto/packets/status/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import json
from typing import Any, ClassVar, final

from attrs import define
from typing_extensions import Self, override

from mcproto.buffer import Buffer
from mcproto.packets.packet import ClientBoundPacket, GameState, ServerBoundPacket
from attrs import define

__all__ = ["StatusRequest", "StatusResponse"]

Expand Down
1 change: 0 additions & 1 deletion mcproto/types/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from mcproto.utils.abc import Serializable


__all__ = ["MCType"]


Expand Down
3 changes: 1 addition & 2 deletions mcproto/types/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import json
from typing import TypedDict, Union, final

from attrs import define
from typing_extensions import Self, TypeAlias, override

from mcproto.buffer import Buffer
from mcproto.types.abc import MCType
from attrs import define


__all__ = [
"ChatMessage",
Expand Down
11 changes: 5 additions & 6 deletions mcproto/types/nbt.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from __future__ import annotations

from abc import abstractmethod
from enum import IntEnum
from typing import ClassVar, Union, cast, Protocol, final, runtime_checkable
from collections.abc import Iterator, Mapping, Sequence
from enum import IntEnum
from typing import ClassVar, Protocol, Union, cast, final, runtime_checkable

from typing_extensions import TypeAlias, override, Self
from attrs import define
from typing_extensions import Self, TypeAlias, override

from mcproto.buffer import Buffer
from mcproto.protocol.base_io import StructFormat, INT_FORMATS_TYPE, FLOAT_FORMATS_TYPE
from mcproto.protocol.base_io import FLOAT_FORMATS_TYPE, INT_FORMATS_TYPE, StructFormat
from mcproto.types.abc import MCType
from attrs import define

from mcproto.utils.abc import RequiredParamsABCMixin

__all__ = [
Expand Down
1 change: 0 additions & 1 deletion mcproto/utils/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from mcproto.buffer import Buffer


__all__ = ["RequiredParamsABCMixin", "Serializable"]


Expand Down
41 changes: 21 additions & 20 deletions poetry.lock

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

63 changes: 13 additions & 50 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pytest-cov = ">=3,<6"
pytest-httpx = { version = ">=0.23.1,<0.25.0", python = ">=3.9,<4" }

[tool.poetry.group.lint.dependencies]
ruff = ">=0.3.4,<0.5.0"
ruff = ">=0.5.0"
pyright = "^1.1.313"
slotscheck = ">=0.16.1,<0.20.0"

Expand All @@ -70,7 +70,7 @@ sphinx-autodoc-typehints = ">=1.23,<3.0"
sphinx-copybutton = "^0.5.2"
furo = ">=2022.12.7"
sphinxcontrib-towncrier = ">=0.3.2,<0.5.0"
pytest = "^7.3.1" # Required to import the gen_test_serializable function to list it in the docs
pytest = "^7.3.1" # Required to import the gen_test_serializable function to list it in the docs

[tool.poetry.group.docs-ci]
optional = true
Expand Down Expand Up @@ -103,56 +103,19 @@ target-version = "py38"
line-length = 119

[tool.ruff.lint]
select = [
"F", # Pyflakes
"E", # Pycodestyle (errors)
"W", # Pycodestyle (warnigns)
"N", # pep8-naming
"D", # pydocstyle
"UP", # pyupgrade
"YTT", # flake8-2020
"ANN", # flake8-annotations
"ASYNC", # flake8-async
"S", # flake8-bandit
"BLE", # flake8-blind-except
"B", # flake8-bugbear
"A", # flake8-builtins
"COM", # flake8-commas
"C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"T10", # flake8-debugger
"EM", # flake8-errmsg
"EXE", # flake8-executable
"FA", # flake8-future-annotations
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
"LOG", # flake8-logging
"G", # flake8-logging-format
"INP", # flake8-no-pep420
"PIE", # flake8-pie
"T20", # flake8-print
"PYI", # flake8-pyi
"PT", # flake8-pytest-style
"Q", # flake8-quotes
"RSE", # flake8-raise
"RET", # flake8-return
"SLOT", # flake8-slots
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"INT", # flake8-gettext
"PTH", # flake8-use-pathlib
"TD", # flake8-todos
"ERA", # flake8-eradicate
"PGH", # pygrep-hooks
"PL", # pylint
"TRY", # tryceratops
"FLY", # flynt
"PERF", # perflint
"RUF", # ruff-specific rules
]
select = ["ALL"]

ignore = [
"C90", # mccabe
"FBT", # flake8-boolean-trap
"CPY", # flake8-copyright
"EM", # flake8-errmsg
"SLF", # flake8-self
"TCH", # flake8-type-checking
"ARG", # flake8-unused-arguments
"TD", # flake8-todos
"FIX", # flake8-fixme

"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
Expand Down
3 changes: 1 addition & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import unittest.mock
from collections.abc import Callable, Coroutine
from typing import Any, Generic, NamedTuple, TypeVar
from typing_extensions import TypeGuard

import pytest
from typing_extensions import ParamSpec, override
from typing_extensions import ParamSpec, TypeGuard, override

from mcproto.buffer import Buffer
from mcproto.utils.abc import Serializable
Expand Down
1 change: 0 additions & 1 deletion tests/mcproto/packets/status/test_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations


from mcproto.packets.status.status import StatusResponse
from tests.helpers import gen_serializable_test

Expand Down
4 changes: 2 additions & 2 deletions tests/mcproto/protocol/test_base_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import platform
import struct
from abc import ABC, abstractmethod
import sys
from typing import TYPE_CHECKING, Any, Generic, TypeVar, Union
from abc import ABC, abstractmethod
from typing import Any, Generic, TYPE_CHECKING, TypeVar, Union
from unittest.mock import AsyncMock, Mock

import pytest
Expand Down
6 changes: 3 additions & 3 deletions tests/mcproto/utils/test_serializable.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import annotations

from typing import Any, cast, final

from attrs import define
from typing_extensions import override

from mcproto.buffer import Buffer
from mcproto.utils.abc import Serializable
from attrs import define

from tests.helpers import gen_serializable_test, TestExc
from tests.helpers import TestExc, gen_serializable_test


class CustomError(Exception):
Expand Down

0 comments on commit 3374434

Please sign in to comment.