diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7920aba23816..0f6051e0bb50 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,13 +13,6 @@ repos: entry: ./activated.py python chia/_tests/build-init-files.py -v --root . language: system pass_filenames: false - - repo: local - hooks: - - id: pyupgrade - name: pyupgrade - entry: ./activated.py pyupgrade --py39-plus --keep-runtime-typing - language: system - types: [python] - repo: local hooks: - id: black diff --git a/chia/_tests/cmds/test_click_types.py b/chia/_tests/cmds/test_click_types.py index 3b3222a974ba..7b46aca19c5d 100644 --- a/chia/_tests/cmds/test_click_types.py +++ b/chia/_tests/cmds/test_click_types.py @@ -67,7 +67,7 @@ def test_click_tx_fee_type() -> None: TransactionFeeParamType().convert(overflow_decimal_str, None, None) # Test Type Failures with pytest.raises(BadParameter): - TransactionFeeParamType().convert(float(0.01), None, None) + TransactionFeeParamType().convert(0.01, None, None) def test_click_amount_type() -> None: @@ -139,7 +139,7 @@ def test_click_address_type() -> None: AddressParamType().convert(burn_bad_prefix, None, None) # Test Type Failures with pytest.raises(BadParameter): - AddressParamType().convert(float(0.01), None, None) + AddressParamType().convert(0.01, None, None) # check class error handling with pytest.raises(ValueError): @@ -170,7 +170,7 @@ def test_click_bytes32_type() -> None: Bytes32ParamType().convert("test", None, None) # Test Type Failures with pytest.raises(BadParameter): - Bytes32ParamType().convert(float(0.01), None, None) + Bytes32ParamType().convert(0.01, None, None) def test_click_uint64_type() -> None: @@ -192,4 +192,4 @@ def test_click_uint64_type() -> None: Uint64ParamType().convert(str(overflow_ammt), None, None) # Test Type Failures with pytest.raises(BadParameter): - Uint64ParamType().convert(float(0.01), None, None) + Uint64ParamType().convert(0.01, None, None) diff --git a/chia/_tests/core/test_seeder.py b/chia/_tests/core/test_seeder.py index 9d4250273698..26cc5c692a07 100644 --- a/chia/_tests/core/test_seeder.py +++ b/chia/_tests/core/test_seeder.py @@ -216,7 +216,7 @@ async def test_error_conditions( r = await dns.asyncquery.tcp(q=no_peers, where=target_address, timeout=timeout, sock=socket) assert r.answer == no_peers_response.answer # send 120, as the first 2 bytes / the length of the packet, so that the server expects more. - await socket.sendall(int(120).to_bytes(2, byteorder="big"), int(time.time() + timeout)) + await socket.sendall((120).to_bytes(2, byteorder="big"), int(time.time() + timeout)) await socket.close() with pytest.raises(EOFError): await dns.asyncquery.receive_tcp(tcp_socket, timeout) diff --git a/chia/_tests/generator/test_rom.py b/chia/_tests/generator/test_rom.py index f98eafe624bd..c59c0b830007 100644 --- a/chia/_tests/generator/test_rom.py +++ b/chia/_tests/generator/test_rom.py @@ -16,7 +16,7 @@ from chia.wallet.puzzles.load_clvm import load_clvm, load_serialized_clvm_maybe_recompile MAX_COST = 10**15 -COST_PER_BYTE = int(12000) +COST_PER_BYTE = 12000 DESERIALIZE_MOD = load_clvm("chialisp_deserialisation.clsp", package_or_requirement="chia.consensus.puzzles") diff --git a/chia/_tests/util/split_managers.py b/chia/_tests/util/split_managers.py index 75a44d0f82e2..cec90f40e56b 100644 --- a/chia/_tests/util/split_managers.py +++ b/chia/_tests/util/split_managers.py @@ -3,7 +3,7 @@ import contextlib from collections.abc import AsyncIterator, Iterator from dataclasses import dataclass -from typing import AsyncContextManager, ContextManager, Generic, TypeVar +from typing import Generic, TypeVar T = TypeVar("T") @@ -11,7 +11,7 @@ @dataclass class SplitManager(Generic[T]): # NOTE: only for transitional testing use, please avoid usage - manager: ContextManager[object] + manager: contextlib.AbstractContextManager[object] object: T _entered: bool = False _exited: bool = False @@ -47,7 +47,7 @@ def exit(self, if_needed: bool = False) -> None: @dataclass class SplitAsyncManager(Generic[T]): # NOTE: only for transitional testing use, please avoid usage - manager: AsyncContextManager[object] + manager: contextlib.AbstractAsyncContextManager[object] object: T _entered: bool = False _exited: bool = False @@ -81,7 +81,7 @@ async def exit(self, if_needed: bool = False) -> None: @contextlib.contextmanager -def split_manager(manager: ContextManager[object], object: T) -> Iterator[SplitManager[T]]: +def split_manager(manager: contextlib.AbstractContextManager[object], object: T) -> Iterator[SplitManager[T]]: # NOTE: only for transitional testing use, please avoid usage split = SplitManager(manager=manager, object=object) try: @@ -91,7 +91,9 @@ def split_manager(manager: ContextManager[object], object: T) -> Iterator[SplitM @contextlib.asynccontextmanager -async def split_async_manager(manager: AsyncContextManager[object], object: T) -> AsyncIterator[SplitAsyncManager[T]]: +async def split_async_manager( + manager: contextlib.AbstractAsyncContextManager[object], object: T +) -> AsyncIterator[SplitAsyncManager[T]]: # NOTE: only for transitional testing use, please avoid usage split = SplitAsyncManager(manager=manager, object=object) try: diff --git a/chia/wallet/trade_manager.py b/chia/wallet/trade_manager.py index cac727ad22e8..1ee542561403 100644 --- a/chia/wallet/trade_manager.py +++ b/chia/wallet/trade_manager.py @@ -4,7 +4,7 @@ import logging import time from collections import deque -from typing import TYPE_CHECKING, Any, Deque, Optional, Union +from typing import TYPE_CHECKING, Any, Optional, Union from typing_extensions import Literal @@ -257,8 +257,8 @@ async def cancel_pending_offers( announcement_nonce: bytes32 = std_hash(b"".join(trades)) trade_records: list[TradeRecord] = [] all_cancellation_coins: list[list[Coin]] = [] - announcement_creations: Deque[CreateCoinAnnouncement] = deque() - announcement_assertions: Deque[AssertCoinAnnouncement] = deque() + announcement_creations: deque[CreateCoinAnnouncement] = deque() + announcement_assertions: deque[AssertCoinAnnouncement] = deque() for trade_id in trades: if trade_id in trade_cache: trade = trade_cache[trade_id] diff --git a/poetry.lock b/poetry.lock index ba5899e6171c..221341c1713f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2556,20 +2556,6 @@ files = [ [package.dependencies] six = ">=1.5" -[[package]] -name = "pyupgrade" -version = "3.16.0" -description = "A tool to automatically upgrade syntax for newer versions." -optional = true -python-versions = ">=3.8.1" -files = [ - {file = "pyupgrade-3.16.0-py2.py3-none-any.whl", hash = "sha256:7a54ee28f3024d027048d49d101e5c702e88c85edc3a1d08b636c50ebef2a97d"}, - {file = "pyupgrade-3.16.0.tar.gz", hash = "sha256:237893a05d5b117259b31b423f23cbae4bce0b7eae57ba9a52c06098c2ddd76f"}, -] - -[package.dependencies] -tokenize-rt = ">=5.2.0" - [[package]] name = "pywin32" version = "306" @@ -2908,17 +2894,6 @@ files = [ {file = "sortedcontainers-2.4.0.tar.gz", hash = "sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88"}, ] -[[package]] -name = "tokenize-rt" -version = "5.2.0" -description = "A wrapper around the stdlib `tokenize` which roundtrips." -optional = true -python-versions = ">=3.8" -files = [ - {file = "tokenize_rt-5.2.0-py2.py3-none-any.whl", hash = "sha256:b79d41a65cfec71285433511b50271b05da3584a1da144a0752e9c621a285289"}, - {file = "tokenize_rt-5.2.0.tar.gz", hash = "sha256:9fe80f8a5c1edad2d3ede0f37481cc0cc1538a2f442c9c2f9e4feacd2792d054"}, -] - [[package]] name = "tomli" version = "2.0.1" @@ -3350,11 +3325,11 @@ url = "https://pypi.chia.net/simple" reference = "chia" [extras] -dev = ["aiohttp_cors", "black", "build", "coverage", "diff-cover", "flake8", "lxml", "mypy", "pre-commit", "pre-commit", "py3createtorrent", "pyinstaller", "pytest", "pytest-cov", "pytest-mock", "pytest-monitor", "pytest-xdist", "pyupgrade", "ruff", "types-aiofiles", "types-cryptography", "types-pyyaml", "types-setuptools"] +dev = ["aiohttp_cors", "black", "build", "coverage", "diff-cover", "flake8", "lxml", "mypy", "pre-commit", "pre-commit", "py3createtorrent", "pyinstaller", "pytest", "pytest-cov", "pytest-mock", "pytest-monitor", "pytest-xdist", "ruff", "types-aiofiles", "types-cryptography", "types-pyyaml", "types-setuptools"] legacy-keyring = ["keyrings.cryptfile"] upnp = ["miniupnpc"] [metadata] lock-version = "2.0" python-versions = ">=3.9, <3.13" -content-hash = "397a0952dcbe106bcfccbf0fb3f2ad6c4e3dbbd44685da7cd53abb5519eb1220" +content-hash = "3d2d4a2b7aad3aadeb05a50c74d0d5288e9c4566c4a436cef3262da9af7dcb76" diff --git a/pyproject.toml b/pyproject.toml index 4199d7ec85e0..6f2b5114f013 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,7 +98,6 @@ types-pyyaml = { version = "6.0.12.20240311", optional = true } types-setuptools = { version = "70.0.0.20240524", optional = true } lxml = { version = "5.2.2", optional = true } miniupnpc = { version = "2.2.2", source = "chia", optional = true } -pyupgrade = { version = "3.16.0", optional = true } # big-o = {version = "0.11.0", optional = true} # numpy = [ # {version="1.24.4", python = "<3.9", optional = true}, @@ -107,7 +106,7 @@ ruff = { version = "0.7.1", optional = true } [tool.poetry.extras] -dev = ["aiohttp_cors", "black", "build", "coverage", "diff-cover", "flake8", "mypy", "pre-commit", "py3createtorrent", "pyinstaller", "pytest", "pytest-cov", "pytest-mock", "pytest-monitor", "pytest-xdist", "ruff", "types-aiofiles", "types-cryptography", "types-pyyaml", "types-setuptools", "pyupgrade", "lxml"] +dev = ["aiohttp_cors", "black", "build", "coverage", "diff-cover", "flake8", "mypy", "pre-commit", "py3createtorrent", "pyinstaller", "pytest", "pytest-cov", "pytest-mock", "pytest-monitor", "pytest-xdist", "ruff", "types-aiofiles", "types-cryptography", "types-pyyaml", "types-setuptools", "lxml"] upnp = ["miniupnpc"] legacy_keyring = ["keyrings.cryptfile"] @@ -155,12 +154,21 @@ include = ''' ''' exclude = '' +[project] +# This has to match the poetry python entry above +requires-python = ">=3.9, <3.13" + [tool.ruff] line-length = 120 [tool.ruff.lint] preview = true -select = ["PL", "I", "FA"] +select = [ + "PL", # Pylint + "I", # Isort + "FA", # Flake8: future-annotations + "UP", # Pyupgrade +] explicit-preview-rules = false ignore = [ # Pylint convention @@ -217,3 +225,6 @@ max-statements = 50 max-nested-blocks = 5 max-public-methods = 20 max-bool-expr = 5 + +[tool.ruff.lint.pyupgrade] +keep-runtime-typing = true