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

Update ruff, switch from black to ruff, fix findings #462

Merged
merged 5 commits into from
Nov 12, 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 .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.3.2
version: 1.8.4
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.6.1
version: 1.8.4
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.3.2
version: 1.8.4
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.3.2
version: 1.8.4
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ clean:
rm -rf dist build __pycache__ *.egg-info

format:
poetry run black src tests
poetry run ruff format src tests

lint:
poetry run black --check --diff src tests
poetry run ruff src tests
poetry run ruff format --check --diff src tests
poetry run ruff check src tests
poetry run mypy src

publish:
Expand Down
77 changes: 22 additions & 55 deletions poetry.lock

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

20 changes: 9 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ websockets = ">=9.0,<12.0"
solders = "^0.21.0"

[tool.poetry.dev-dependencies]
black = "^22.3"
pytest = "^7.4.3"
mypy = "^1.0"
pyyaml = "6.0.1"
Expand All @@ -45,7 +44,7 @@ pytest-cov = "^3.0.0"
asyncstdlib = "^3.10.2"
mkdocstrings = "^0.18.0"
mkdocs-material = "^8.2.1"
ruff = "^0.0.219"
ruff = "^0.7.3"


[build-system]
Expand All @@ -54,7 +53,10 @@ build-backend = "poetry.core.masonry.api"

[tool.ruff]
line-length = 120
# Assume Python 3.10.
target-version = "py310"

[tool.ruff.lint]
# Enable Pyflakes `E` and `F` codes by default.
select = [
"A",
Expand Down Expand Up @@ -101,18 +103,14 @@ exclude = [
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.10.
target-version = "py310"

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"src/**/*.py" = ["PLR0913", "RUF012"]
"src/solana/blockhash.py" = ["A003"]
"tests/**/*.py" = ["D100", "D103", "ARG001"]

[tool.black]
line-length = 120
"src/solana/rpc/api.py" = ["PLR0912"]
"tests/**/*.py" = ["D100", "D103", "ARG001", "PLR2004"]

[tool.pyright]
reportMissingModuleSource = false
Expand Down
2 changes: 1 addition & 1 deletion src/solana/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
import sys

if sys.version_info < (3, 7):
raise EnvironmentError("Python 3.7 or above is required.") # noqa: E501
raise EnvironmentError("Python 3.7 or above is required.")
1 change: 1 addition & 0 deletions src/solana/_layouts/vote_instructions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Byte layouts for vote program instructions."""

from enum import IntEnum

from construct import (
Expand Down
4 changes: 2 additions & 2 deletions src/solana/rpc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ def get_stake_activation(
>>> solana_client.get_stake_activation().value.active # doctest: +SKIP
124429280
"""
warn("get_stake_activation is deprecated. Use get_account_info instead.", DeprecationWarning)
warn("get_stake_activation is deprecated. Use get_account_info instead.", DeprecationWarning, stacklevel=1)
body = self._get_stake_activation_body(pubkey, epoch, commitment)
return self._provider.make_request(body, GetStakeActivationResp)

Expand Down Expand Up @@ -1035,7 +1035,7 @@ def send_legacy_transaction(
1111111111111111111111111111111111111111111111111111111111111111,
)
"""
warn("send_legacy_transaction is deprecated. Use send_transaction instead.", DeprecationWarning)
warn("send_legacy_transaction is deprecated. Use send_transaction instead.", DeprecationWarning, stacklevel=1)

last_valid_block_height = None
if recent_blockhash is None:
Expand Down
4 changes: 2 additions & 2 deletions src/solana/rpc/async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ async def get_stake_activation(
>>> (await solana_client.get_stake_activation()).value.active # doctest: +SKIP
124429280
"""
warn("get_stake_activation is deprecated. Use get_account_info instead.", DeprecationWarning)
warn("get_stake_activation is deprecated. Use get_account_info instead.", DeprecationWarning, stacklevel=1)
body = self._get_stake_activation_body(pubkey, epoch, commitment)
return await self._provider.make_request(body, GetStakeActivationResp)

Expand Down Expand Up @@ -1046,7 +1046,7 @@ async def send_legacy_transaction(
1111111111111111111111111111111111111111111111111111111111111111,
)
"""
warn("send_legacy_transaction is deprecated. Use send_transaction instead.", DeprecationWarning)
warn("send_legacy_transaction is deprecated. Use send_transaction instead.", DeprecationWarning, stacklevel=1)

last_valid_block_height = None
if recent_blockhash is None:
Expand Down
1 change: 1 addition & 0 deletions src/solana/rpc/commitment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

In descending order of commitment (most finalized to least finalized), clients may specify:
"""

from typing import NewType

Commitment = NewType("Commitment", str)
Expand Down
14 changes: 8 additions & 6 deletions src/solana/rpc/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pylint: disable=too-many-arguments
"""Helper code for api.py and async_api.py."""

from typing import List, Optional, Sequence, Tuple, Union, overload

from solders.account_decoder import UiAccountEncoding, UiDataSliceConfig
Expand Down Expand Up @@ -380,7 +381,11 @@ def _get_token_accounts_convert(
pubkey: Pubkey,
opts: types.TokenAccountOpts,
commitment: Optional[Commitment],
) -> Tuple[Pubkey, Union[RpcTokenAccountsFilterMint, RpcTokenAccountsFilterProgramId], RpcAccountInfoConfig,]:
) -> Tuple[
Pubkey,
Union[RpcTokenAccountsFilterMint, RpcTokenAccountsFilterProgramId],
RpcAccountInfoConfig,
]:
commitment_to_use = _COMMITMENT_TO_SOLDERS[commitment or self._commitment]
encoding_to_use = _ACCOUNT_ENCODING_TO_SOLDERS[opts.encoding]
maybe_data_slice = opts.data_slice
Expand Down Expand Up @@ -487,14 +492,12 @@ def _send_raw_transaction_post_send_args(
@overload
def _simulate_transaction_body(
self, txn: Transaction, sig_verify: bool, commitment: Optional[Commitment]
) -> SimulateLegacyTransaction:
...
) -> SimulateLegacyTransaction: ...

@overload
def _simulate_transaction_body(
self, txn: VersionedTransaction, sig_verify: bool, commitment: Optional[Commitment]
) -> SimulateVersionedTransaction:
...
) -> SimulateVersionedTransaction: ...

def _simulate_transaction_body(
self, txn: Union[Transaction, VersionedTransaction], sig_verify: bool, commitment: Optional[Commitment]
Expand All @@ -507,7 +510,6 @@ def _simulate_transaction_body(

@staticmethod
def _post_send(resp: SendTransactionResp) -> SendTransactionResp:

if isinstance(resp, InvalidParamsMessage):
raise RPCNoResultException(resp.message)

Expand Down
1 change: 1 addition & 0 deletions src/solana/rpc/providers/async_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Async base RPC Provider."""

from typing import Type

from solders.rpc.requests import Body
Expand Down
19 changes: 7 additions & 12 deletions src/solana/rpc/providers/async_http.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Async HTTP RPC Provider."""

from typing import Dict, Optional, Tuple, Type, overload

import httpx
Expand Down Expand Up @@ -72,28 +73,22 @@ async def make_batch_request_unparsed(self, reqs: Tuple[Body, ...]) -> str:
return _after_request_unparsed(raw_response)

@overload
async def make_batch_request(self, reqs: _BodiesTup, parsers: _Tup) -> _RespTup:
...
async def make_batch_request(self, reqs: _BodiesTup, parsers: _Tup) -> _RespTup: ...

@overload
async def make_batch_request(self, reqs: _BodiesTup1, parsers: _Tup1) -> _RespTup1:
...
async def make_batch_request(self, reqs: _BodiesTup1, parsers: _Tup1) -> _RespTup1: ...

@overload
async def make_batch_request(self, reqs: _BodiesTup2, parsers: _Tup2) -> _RespTup2:
...
async def make_batch_request(self, reqs: _BodiesTup2, parsers: _Tup2) -> _RespTup2: ...

@overload
async def make_batch_request(self, reqs: _BodiesTup3, parsers: _Tup3) -> _RespTup3:
...
async def make_batch_request(self, reqs: _BodiesTup3, parsers: _Tup3) -> _RespTup3: ...

@overload
async def make_batch_request(self, reqs: _BodiesTup4, parsers: _Tup4) -> _RespTup4:
...
async def make_batch_request(self, reqs: _BodiesTup4, parsers: _Tup4) -> _RespTup4: ...

@overload
async def make_batch_request(self, reqs: _BodiesTup5, parsers: _Tup5) -> _RespTup5:
...
async def make_batch_request(self, reqs: _BodiesTup5, parsers: _Tup5) -> _RespTup5: ...

async def make_batch_request(self, reqs: Tuple[Body, ...], parsers: _Tuples) -> Tuple[RPCResult, ...]:
"""Make an async HTTP batch request to an http rpc endpoint.
Expand Down
1 change: 1 addition & 0 deletions src/solana/rpc/providers/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base RPC Provider."""

from solders.rpc.requests import Body
from typing_extensions import Type

Expand Down
Loading