Skip to content

Commit

Permalink
[CHIA-1679] Replace Pyupgrade with Ruff (#18795)
Browse files Browse the repository at this point in the history
* Replace Pyupgrade with Ruff

* Fix python version
  • Loading branch information
Quexington authored Oct 31, 2024
1 parent 68adc50 commit efb7a29
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 51 deletions.
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions chia/_tests/cmds/test_click_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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)
2 changes: 1 addition & 1 deletion chia/_tests/core/test_seeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/generator/test_rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 7 additions & 5 deletions chia/_tests/util/split_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
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")


@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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions chia/wallet/trade_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down
29 changes: 2 additions & 27 deletions poetry.lock

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

17 changes: 14 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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"]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit efb7a29

Please sign in to comment.