diff --git a/changes/323.internal.md b/changes/323.internal.md new file mode 100644 index 00000000..ab112ded --- /dev/null +++ b/changes/323.internal.md @@ -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. diff --git a/docs/conf.py b/docs/conf.py index e14cbd82..297169d3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 diff --git a/mcproto/connection.py b/mcproto/connection.py index bcc15bd0..733fdaf1 100644 --- a/mcproto/connection.py +++ b/mcproto/connection.py @@ -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 @@ -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 diff --git a/mcproto/encryption.py b/mcproto/encryption.py index 509a22a4..d702dc13 100644 --- a/mcproto/encryption.py +++ b/mcproto/encryption.py @@ -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()) @@ -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()) diff --git a/mcproto/packets/handshaking/handshake.py b/mcproto/packets/handshaking/handshake.py index fe3b5510..7d96958d 100644 --- a/mcproto/packets/handshaking/handshake.py +++ b/mcproto/packets/handshaking/handshake.py @@ -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", diff --git a/mcproto/packets/login/login.py b/mcproto/packets/login/login.py index 367d334d..63557fc4 100644 --- a/mcproto/packets/login/login.py +++ b/mcproto/packets/login/login.py @@ -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 @@ -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", diff --git a/mcproto/packets/status/ping.py b/mcproto/packets/status/ping.py index 6816e3fc..e638a36c 100644 --- a/mcproto/packets/status/ping.py +++ b/mcproto/packets/status/ping.py @@ -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"] diff --git a/mcproto/packets/status/status.py b/mcproto/packets/status/status.py index 63cf7cad..2bebe15b 100644 --- a/mcproto/packets/status/status.py +++ b/mcproto/packets/status/status.py @@ -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"] diff --git a/mcproto/types/abc.py b/mcproto/types/abc.py index 5019381b..03614720 100644 --- a/mcproto/types/abc.py +++ b/mcproto/types/abc.py @@ -2,7 +2,6 @@ from mcproto.utils.abc import Serializable - __all__ = ["MCType"] diff --git a/mcproto/types/chat.py b/mcproto/types/chat.py index cdd23783..2c722fc3 100644 --- a/mcproto/types/chat.py +++ b/mcproto/types/chat.py @@ -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", diff --git a/mcproto/types/nbt.py b/mcproto/types/nbt.py index 0a6e23ca..1c9cdb57 100644 --- a/mcproto/types/nbt.py +++ b/mcproto/types/nbt.py @@ -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__ = [ diff --git a/mcproto/utils/abc.py b/mcproto/utils/abc.py index 7dc6d3ed..a03f73d4 100644 --- a/mcproto/utils/abc.py +++ b/mcproto/utils/abc.py @@ -8,7 +8,6 @@ from mcproto.buffer import Buffer - __all__ = ["RequiredParamsABCMixin", "Serializable"] diff --git a/poetry.lock b/poetry.lock index 759469e2..e91e4cd2 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. + # This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "alabaster" @@ -1132,28 +1132,29 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "ruff" -version = "0.4.9" +version = "0.5.0" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.4.9-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:b262ed08d036ebe162123170b35703aaf9daffecb698cd367a8d585157732991"}, - {file = "ruff-0.4.9-py3-none-macosx_11_0_arm64.whl", hash = "sha256:98ec2775fd2d856dc405635e5ee4ff177920f2141b8e2d9eb5bd6efd50e80317"}, - {file = "ruff-0.4.9-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4555056049d46d8a381f746680db1c46e67ac3b00d714606304077682832998e"}, - {file = "ruff-0.4.9-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e91175fbe48f8a2174c9aad70438fe9cb0a5732c4159b2a10a3565fea2d94cde"}, - {file = "ruff-0.4.9-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:0e8e7b95673f22e0efd3571fb5b0cf71a5eaaa3cc8a776584f3b2cc878e46bff"}, - {file = "ruff-0.4.9-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:2d45ddc6d82e1190ea737341326ecbc9a61447ba331b0a8962869fcada758505"}, - {file = "ruff-0.4.9-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:78de3fdb95c4af084087628132336772b1c5044f6e710739d440fc0bccf4d321"}, - {file = "ruff-0.4.9-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:06b60f91bfa5514bb689b500a25ba48e897d18fea14dce14b48a0c40d1635893"}, - {file = "ruff-0.4.9-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:88bffe9c6a454bf8529f9ab9091c99490578a593cc9f9822b7fc065ee0712a06"}, - {file = "ruff-0.4.9-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:673bddb893f21ab47a8334c8e0ea7fd6598ecc8e698da75bcd12a7b9d0a3206e"}, - {file = "ruff-0.4.9-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:8c1aff58c31948cc66d0b22951aa19edb5af0a3af40c936340cd32a8b1ab7438"}, - {file = "ruff-0.4.9-py3-none-musllinux_1_2_i686.whl", hash = "sha256:784d3ec9bd6493c3b720a0b76f741e6c2d7d44f6b2be87f5eef1ae8cc1d54c84"}, - {file = "ruff-0.4.9-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:732dd550bfa5d85af8c3c6cbc47ba5b67c6aed8a89e2f011b908fc88f87649db"}, - {file = "ruff-0.4.9-py3-none-win32.whl", hash = "sha256:8064590fd1a50dcf4909c268b0e7c2498253273309ad3d97e4a752bb9df4f521"}, - {file = "ruff-0.4.9-py3-none-win_amd64.whl", hash = "sha256:e0a22c4157e53d006530c902107c7f550b9233e9706313ab57b892d7197d8e52"}, - {file = "ruff-0.4.9-py3-none-win_arm64.whl", hash = "sha256:5d5460f789ccf4efd43f265a58538a2c24dbce15dbf560676e430375f20a8198"}, - {file = "ruff-0.4.9.tar.gz", hash = "sha256:f1cb0828ac9533ba0135d148d214e284711ede33640465e706772645483427e3"}, + {file = "ruff-0.5.0-py3-none-linux_armv6l.whl", hash = "sha256:ee770ea8ab38918f34e7560a597cc0a8c9a193aaa01bfbd879ef43cb06bd9c4c"}, + {file = "ruff-0.5.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:38f3b8327b3cb43474559d435f5fa65dacf723351c159ed0dc567f7ab735d1b6"}, + {file = "ruff-0.5.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:7594f8df5404a5c5c8f64b8311169879f6cf42142da644c7e0ba3c3f14130370"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:adc7012d6ec85032bc4e9065110df205752d64010bed5f958d25dbee9ce35de3"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:d505fb93b0fabef974b168d9b27c3960714d2ecda24b6ffa6a87ac432905ea38"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9dc5cfd3558f14513ed0d5b70ce531e28ea81a8a3b1b07f0f48421a3d9e7d80a"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:db3ca35265de239a1176d56a464b51557fce41095c37d6c406e658cf80bbb362"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b1a321c4f68809fddd9b282fab6a8d8db796b270fff44722589a8b946925a2a8"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2c4dfcd8d34b143916994b3876b63d53f56724c03f8c1a33a253b7b1e6bf2a7d"}, + {file = "ruff-0.5.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:81e5facfc9f4a674c6a78c64d38becfbd5e4f739c31fcd9ce44c849f1fad9e4c"}, + {file = "ruff-0.5.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:e589e27971c2a3efff3fadafb16e5aef7ff93250f0134ec4b52052b673cf988d"}, + {file = "ruff-0.5.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:d2ffbc3715a52b037bcb0f6ff524a9367f642cdc5817944f6af5479bbb2eb50e"}, + {file = "ruff-0.5.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:cd096e23c6a4f9c819525a437fa0a99d1c67a1b6bb30948d46f33afbc53596cf"}, + {file = "ruff-0.5.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:46e193b36f2255729ad34a49c9a997d506e58f08555366b2108783b3064a0e1e"}, + {file = "ruff-0.5.0-py3-none-win32.whl", hash = "sha256:49141d267100f5ceff541b4e06552e98527870eafa1acc9dec9139c9ec5af64c"}, + {file = "ruff-0.5.0-py3-none-win_amd64.whl", hash = "sha256:e9118f60091047444c1b90952736ee7b1792910cab56e9b9a9ac20af94cd0440"}, + {file = "ruff-0.5.0-py3-none-win_arm64.whl", hash = "sha256:ed5c4df5c1fb4518abcb57725b576659542bdbe93366f4f329e8f398c4b71178"}, + {file = "ruff-0.5.0.tar.gz", hash = "sha256:eb641b5873492cf9bd45bc9c5ae5320648218e04386a5f0c264ad6ccce8226a1"}, ] [[package]] @@ -1553,4 +1554,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<4" -content-hash = "6494da8d67ef4a8c6458fbfcba8fc168a41b9ee74ce84d54dda9112915d99e21" +content-hash = "d2a651e97fa62906207eb9fa52ae4d73304ff333c19ca0b903bf24a88e73d462" diff --git a/pyproject.toml b/pyproject.toml index 3fcf3554..8940ec96 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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 @@ -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 diff --git a/tests/helpers.py b/tests/helpers.py index 9ecae3e2..5d643b7b 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -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 diff --git a/tests/mcproto/packets/status/test_status.py b/tests/mcproto/packets/status/test_status.py index 8bc377d4..63459ba2 100644 --- a/tests/mcproto/packets/status/test_status.py +++ b/tests/mcproto/packets/status/test_status.py @@ -1,6 +1,5 @@ from __future__ import annotations - from mcproto.packets.status.status import StatusResponse from tests.helpers import gen_serializable_test diff --git a/tests/mcproto/protocol/test_base_io.py b/tests/mcproto/protocol/test_base_io.py index 54abe1db..4d50c497 100644 --- a/tests/mcproto/protocol/test_base_io.py +++ b/tests/mcproto/protocol/test_base_io.py @@ -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 diff --git a/tests/mcproto/utils/test_serializable.py b/tests/mcproto/utils/test_serializable.py index 5f1537c7..b02248a6 100644 --- a/tests/mcproto/utils/test_serializable.py +++ b/tests/mcproto/utils/test_serializable.py @@ -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):