From 3f40b01cb6aefb79259ca7ed8cff573ab1f02de0 Mon Sep 17 00:00:00 2001 From: Daniel Bast <2790401+dbast@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:06:38 +0100 Subject: [PATCH] Update ruff, switch from black to ruff, fix findings (#462) --- .github/workflows/docs.yml | 2 +- .github/workflows/main.yml | 4 +- .github/workflows/release.yml | 2 +- Makefile | 6 +- poetry.lock | 77 ++++++-------------- pyproject.toml | 20 +++-- src/solana/__init__.py | 2 +- src/solana/_layouts/vote_instructions.py | 1 + src/solana/rpc/api.py | 4 +- src/solana/rpc/async_api.py | 4 +- src/solana/rpc/commitment.py | 1 + src/solana/rpc/core.py | 14 ++-- src/solana/rpc/providers/async_base.py | 1 + src/solana/rpc/providers/async_http.py | 19 ++--- src/solana/rpc/providers/base.py | 1 + src/solana/rpc/providers/core.py | 36 +++------ src/solana/rpc/providers/http.py | 19 ++--- src/solana/rpc/types.py | 3 +- src/solana/transaction.py | 8 +- src/solana/utils/security_txt.py | 1 - src/solana/utils/validate.py | 1 + src/solana/vote_program.py | 2 + src/spl/memo/constants.py | 1 + src/spl/memo/instructions.py | 1 + src/spl/token/_layouts.py | 1 + src/spl/token/async_client.py | 9 ++- src/spl/token/client.py | 9 ++- src/spl/token/core.py | 5 +- tests/conftest.py | 5 +- tests/integration/test_async_http_client.py | 1 + tests/integration/test_async_token_client.py | 32 +++----- tests/integration/test_http_client.py | 9 ++- tests/integration/test_memo.py | 1 + tests/integration/test_token_client.py | 37 +++------- tests/integration/test_websockets.py | 5 +- tests/unit/test_async_client.py | 1 + tests/unit/test_client.py | 1 + tests/unit/test_legacy_transaction.py | 1 + tests/unit/test_spl_token_instructions.py | 1 + tests/unit/test_vote_program.py | 5 +- tests/utils.py | 1 + 41 files changed, 153 insertions(+), 201 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 61cbe79c..afdda49c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -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 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b9c0fe6e..d6c49b9a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index baa77dc8..cb73164a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/Makefile b/Makefile index 33e401d7..a2e4129b 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/poetry.lock b/poetry.lock index ba3a40c0..7e1d6d58 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. [[package]] name = "anyio" @@ -71,41 +71,6 @@ tests = ["attrs[tests-no-zope]", "zope-interface"] tests-mypy = ["mypy (>=1.6)", "pytest-mypy-plugins"] tests-no-zope = ["attrs[tests-mypy]", "cloudpickle", "hypothesis", "pympler", "pytest (>=4.3.0)", "pytest-xdist[psutil]"] -[[package]] -name = "black" -version = "22.12.0" -description = "The uncompromising code formatter." -optional = false -python-versions = ">=3.7" -files = [ - {file = "black-22.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9eedd20838bd5d75b80c9f5487dbcb06836a43833a37846cf1d8c1cc01cef59d"}, - {file = "black-22.12.0-cp310-cp310-win_amd64.whl", hash = "sha256:159a46a4947f73387b4d83e87ea006dbb2337eab6c879620a3ba52699b1f4351"}, - {file = "black-22.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d30b212bffeb1e252b31dd269dfae69dd17e06d92b87ad26e23890f3efea366f"}, - {file = "black-22.12.0-cp311-cp311-win_amd64.whl", hash = "sha256:7412e75863aa5c5411886804678b7d083c7c28421210180d67dfd8cf1221e1f4"}, - {file = "black-22.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c116eed0efb9ff870ded8b62fe9f28dd61ef6e9ddd28d83d7d264a38417dcee2"}, - {file = "black-22.12.0-cp37-cp37m-win_amd64.whl", hash = "sha256:1f58cbe16dfe8c12b7434e50ff889fa479072096d79f0a7f25e4ab8e94cd8350"}, - {file = "black-22.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:77d86c9f3db9b1bf6761244bc0b3572a546f5fe37917a044e02f3166d5aafa7d"}, - {file = "black-22.12.0-cp38-cp38-win_amd64.whl", hash = "sha256:82d9fe8fee3401e02e79767016b4907820a7dc28d70d137eb397b92ef3cc5bfc"}, - {file = "black-22.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:101c69b23df9b44247bd88e1d7e90154336ac4992502d4197bdac35dd7ee3320"}, - {file = "black-22.12.0-cp39-cp39-win_amd64.whl", hash = "sha256:559c7a1ba9a006226f09e4916060982fd27334ae1998e7a38b3f33a37f7a2148"}, - {file = "black-22.12.0-py3-none-any.whl", hash = "sha256:436cc9167dd28040ad90d3b404aec22cedf24a6e4d7de221bec2730ec0c97bcf"}, - {file = "black-22.12.0.tar.gz", hash = "sha256:229351e5a18ca30f447bf724d007f890f97e13af070bb6ad4c0a441cd7596a2f"}, -] - -[package.dependencies] -click = ">=8.0.0" -mypy-extensions = ">=0.4.3" -pathspec = ">=0.9.0" -platformdirs = ">=2" -tomli = {version = ">=1.1.0", markers = "python_full_version < \"3.11.0a7\""} -typing-extensions = {version = ">=3.10.0.0", markers = "python_version < \"3.10\""} - -[package.extras] -colorama = ["colorama (>=0.4.3)"] -d = ["aiohttp (>=3.7.4)"] -jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] -uvloop = ["uvloop (>=0.15.2)"] - [[package]] name = "bump2version" version = "1.0.1" @@ -979,27 +944,29 @@ use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] [[package]] name = "ruff" -version = "0.0.219" -description = "An extremely fast Python linter, written in Rust." +version = "0.7.3" +description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.0.219-py3-none-macosx_10_7_x86_64.whl", hash = "sha256:8b3cc1a7136d2352b24aa5508c360312a9f0404ab3e9a39077e1e1824860e266"}, - {file = "ruff-0.0.219-py3-none-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", hash = "sha256:e80a44fac216f99e1243a713a2199049d7a1c5133582b88167a688e638ce959e"}, - {file = "ruff-0.0.219-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6e35d9e1e1fbf98cb7193e64ead3b28ea73c79f4b30b14ab1e53896a89aee57f"}, - {file = "ruff-0.0.219-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:6c3c59f37ce96a513ec1e6d370f9fe694d722acf448804dc8914bf30b92b22af"}, - {file = "ruff-0.0.219-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:65e623405709782264242b998d6b102324749b5dc2eafbb1519ab15b4721a37b"}, - {file = "ruff-0.0.219-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:4f6e954adf4399475cf56ad7ebb02200e6aa509e4c76ffa46a6390efa1008c68"}, - {file = "ruff-0.0.219-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5a6ac247301269b0d269760f2b9c7067ce9f337a5bebbf68d639b9524e71f702"}, - {file = "ruff-0.0.219-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:0fe2828ed6aa191b841a3f5a1b368e974cc7ccde3a592ebd78236c463a78993d"}, - {file = "ruff-0.0.219-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:704a1f3b05602cce5ffa0ce7c1960aa8ba8c18a2085dfbf52d7b8a665ba53163"}, - {file = "ruff-0.0.219-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:ddca12bcfd0d2d86638b7c592883c187354074e5f3ce236617760562ae3176f3"}, - {file = "ruff-0.0.219-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:c4d473b6a18e1588072275f5a0c575d730760f36297f1e21cca7c32dc0bd9c51"}, - {file = "ruff-0.0.219-py3-none-musllinux_1_2_i686.whl", hash = "sha256:49adacdd1fd0272651be67bc555c07c43f454a64e0b7c09266405402233bd234"}, - {file = "ruff-0.0.219-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:ce1824f70bcf5ec294e42da2e5bd8ab6fbb1ea0549bd47113e062df5575ee2c2"}, - {file = "ruff-0.0.219-py3-none-win32.whl", hash = "sha256:0e6c553eb24e956644f465db715b21ac93254645cbd2078b2e70bf7aff5c5856"}, - {file = "ruff-0.0.219-py3-none-win_amd64.whl", hash = "sha256:001ab73b8517aa6ddfa739c444fd6952a7d9d043785147aa37440ebba45e2920"}, - {file = "ruff-0.0.219.tar.gz", hash = "sha256:1ec1f3e859b5934be394e780c87d615a34c93ffc223135ba2ee9579674e352a8"}, + {file = "ruff-0.7.3-py3-none-linux_armv6l.whl", hash = "sha256:34f2339dc22687ec7e7002792d1f50712bf84a13d5152e75712ac08be565d344"}, + {file = "ruff-0.7.3-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:fb397332a1879b9764a3455a0bb1087bda876c2db8aca3a3cbb67b3dbce8cda0"}, + {file = "ruff-0.7.3-py3-none-macosx_11_0_arm64.whl", hash = "sha256:37d0b619546103274e7f62643d14e1adcbccb242efda4e4bdb9544d7764782e9"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5d59f0c3ee4d1a6787614e7135b72e21024875266101142a09a61439cb6e38a5"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:44eb93c2499a169d49fafd07bc62ac89b1bc800b197e50ff4633aed212569299"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6d0242ce53f3a576c35ee32d907475a8d569944c0407f91d207c8af5be5dae4e"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:6b6224af8b5e09772c2ecb8dc9f3f344c1aa48201c7f07e7315367f6dd90ac29"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c50f95a82b94421c964fae4c27c0242890a20fe67d203d127e84fbb8013855f5"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7f3eff9961b5d2644bcf1616c606e93baa2d6b349e8aa8b035f654df252c8c67"}, + {file = "ruff-0.7.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b8963cab06d130c4df2fd52c84e9f10d297826d2e8169ae0c798b6221be1d1d2"}, + {file = "ruff-0.7.3-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:61b46049d6edc0e4317fb14b33bd693245281a3007288b68a3f5b74a22a0746d"}, + {file = "ruff-0.7.3-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:10ebce7696afe4644e8c1a23b3cf8c0f2193a310c18387c06e583ae9ef284de2"}, + {file = "ruff-0.7.3-py3-none-musllinux_1_2_i686.whl", hash = "sha256:3f36d56326b3aef8eeee150b700e519880d1aab92f471eefdef656fd57492aa2"}, + {file = "ruff-0.7.3-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5d024301109a0007b78d57ab0ba190087b43dce852e552734ebf0b0b85e4fb16"}, + {file = "ruff-0.7.3-py3-none-win32.whl", hash = "sha256:4ba81a5f0c5478aa61674c5a2194de8b02652f17addf8dfc40c8937e6e7d79fc"}, + {file = "ruff-0.7.3-py3-none-win_amd64.whl", hash = "sha256:588a9ff2fecf01025ed065fe28809cd5a53b43505f48b69a1ac7707b1b7e4088"}, + {file = "ruff-0.7.3-py3-none-win_arm64.whl", hash = "sha256:1713e2c5545863cdbfe2cbce21f69ffaf37b813bfd1fb3b90dc9a6f1963f5a8c"}, + {file = "ruff-0.7.3.tar.gz", hash = "sha256:e1d1ba2e40b6e71a61b063354d04be669ab0d39c352461f3d789cac68b54a313"}, ] [[package]] @@ -1236,4 +1203,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "760ad72914c21752b5baa25a29b143ac822d930d612a55a48bca00f24e865569" +content-hash = "95541beeaeba0fe21c852107e904bffae12313c0c1149fd5e41f3c93a0623c7c" diff --git a/pyproject.toml b/pyproject.toml index 360ac0a6..66efdf28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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] @@ -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", @@ -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 diff --git a/src/solana/__init__.py b/src/solana/__init__.py index 3f34dbef..b97f19cd 100644 --- a/src/solana/__init__.py +++ b/src/solana/__init__.py @@ -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.") diff --git a/src/solana/_layouts/vote_instructions.py b/src/solana/_layouts/vote_instructions.py index 4dafcffc..fb475c34 100644 --- a/src/solana/_layouts/vote_instructions.py +++ b/src/solana/_layouts/vote_instructions.py @@ -1,4 +1,5 @@ """Byte layouts for vote program instructions.""" + from enum import IntEnum from construct import ( diff --git a/src/solana/rpc/api.py b/src/solana/rpc/api.py index b5d06783..47f69a09 100644 --- a/src/solana/rpc/api.py +++ b/src/solana/rpc/api.py @@ -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) @@ -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: diff --git a/src/solana/rpc/async_api.py b/src/solana/rpc/async_api.py index c176cbdb..b655ed70 100644 --- a/src/solana/rpc/async_api.py +++ b/src/solana/rpc/async_api.py @@ -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) @@ -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: diff --git a/src/solana/rpc/commitment.py b/src/solana/rpc/commitment.py index b0f9dbbe..e3bfb8cf 100644 --- a/src/solana/rpc/commitment.py +++ b/src/solana/rpc/commitment.py @@ -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) diff --git a/src/solana/rpc/core.py b/src/solana/rpc/core.py index 10063137..bbc5cafb 100644 --- a/src/solana/rpc/core.py +++ b/src/solana/rpc/core.py @@ -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 @@ -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 @@ -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] @@ -507,7 +510,6 @@ def _simulate_transaction_body( @staticmethod def _post_send(resp: SendTransactionResp) -> SendTransactionResp: - if isinstance(resp, InvalidParamsMessage): raise RPCNoResultException(resp.message) diff --git a/src/solana/rpc/providers/async_base.py b/src/solana/rpc/providers/async_base.py index 29ce1184..8e1500db 100644 --- a/src/solana/rpc/providers/async_base.py +++ b/src/solana/rpc/providers/async_base.py @@ -1,4 +1,5 @@ """Async base RPC Provider.""" + from typing import Type from solders.rpc.requests import Body diff --git a/src/solana/rpc/providers/async_http.py b/src/solana/rpc/providers/async_http.py index 441b1993..1ac8c8dd 100644 --- a/src/solana/rpc/providers/async_http.py +++ b/src/solana/rpc/providers/async_http.py @@ -1,4 +1,5 @@ """Async HTTP RPC Provider.""" + from typing import Dict, Optional, Tuple, Type, overload import httpx @@ -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. diff --git a/src/solana/rpc/providers/base.py b/src/solana/rpc/providers/base.py index 771cc122..85ffcb84 100644 --- a/src/solana/rpc/providers/base.py +++ b/src/solana/rpc/providers/base.py @@ -1,4 +1,5 @@ """Base RPC Provider.""" + from solders.rpc.requests import Body from typing_extensions import Type diff --git a/src/solana/rpc/providers/core.py b/src/solana/rpc/providers/core.py index 3e2b8afb..06d44d7a 100644 --- a/src/solana/rpc/providers/core.py +++ b/src/solana/rpc/providers/core.py @@ -100,33 +100,27 @@ def _parse_raw(raw: str, parser: Type[T]) -> T: @overload -def _parse_raw_batch(raw: str, parsers: _Tup) -> _RespTup: - ... +def _parse_raw_batch(raw: str, parsers: _Tup) -> _RespTup: ... @overload -def _parse_raw_batch(raw: str, parsers: _Tup1) -> _RespTup1: - ... +def _parse_raw_batch(raw: str, parsers: _Tup1) -> _RespTup1: ... @overload -def _parse_raw_batch(raw: str, parsers: _Tup2) -> _RespTup2: - ... +def _parse_raw_batch(raw: str, parsers: _Tup2) -> _RespTup2: ... @overload -def _parse_raw_batch(raw: str, parsers: _Tup3) -> _RespTup3: - ... +def _parse_raw_batch(raw: str, parsers: _Tup3) -> _RespTup3: ... @overload -def _parse_raw_batch(raw: str, parsers: _Tup4) -> _RespTup4: - ... +def _parse_raw_batch(raw: str, parsers: _Tup4) -> _RespTup4: ... @overload -def _parse_raw_batch(raw: str, parsers: _Tup5) -> _RespTup5: - ... +def _parse_raw_batch(raw: str, parsers: _Tup5) -> _RespTup5: ... def _parse_raw_batch(raw: str, parsers: _Tuples) -> Tuple[RPCResult, ...]: @@ -139,33 +133,27 @@ def _after_request_unparsed(raw_response: httpx.Response) -> str: @overload -def _after_batch_request(raw_response: httpx.Response, parsers: _Tup) -> _RespTup: - ... +def _after_batch_request(raw_response: httpx.Response, parsers: _Tup) -> _RespTup: ... @overload -def _after_batch_request(raw_response: httpx.Response, parsers: _Tup1) -> _RespTup1: - ... +def _after_batch_request(raw_response: httpx.Response, parsers: _Tup1) -> _RespTup1: ... @overload -def _after_batch_request(raw_response: httpx.Response, parsers: _Tup2) -> _RespTup2: - ... +def _after_batch_request(raw_response: httpx.Response, parsers: _Tup2) -> _RespTup2: ... @overload -def _after_batch_request(raw_response: httpx.Response, parsers: _Tup3) -> _RespTup3: - ... +def _after_batch_request(raw_response: httpx.Response, parsers: _Tup3) -> _RespTup3: ... @overload -def _after_batch_request(raw_response: httpx.Response, parsers: _Tup4) -> _RespTup4: - ... +def _after_batch_request(raw_response: httpx.Response, parsers: _Tup4) -> _RespTup4: ... @overload -def _after_batch_request(raw_response: httpx.Response, parsers: _Tup5) -> _RespTup5: - ... +def _after_batch_request(raw_response: httpx.Response, parsers: _Tup5) -> _RespTup5: ... def _after_batch_request(raw_response: httpx.Response, parsers: _Tuples) -> Tuple[RPCResult, ...]: diff --git a/src/solana/rpc/providers/http.py b/src/solana/rpc/providers/http.py index fd2e555e..46214c5d 100644 --- a/src/solana/rpc/providers/http.py +++ b/src/solana/rpc/providers/http.py @@ -1,4 +1,5 @@ """HTTP RPC Provider.""" + from typing import Tuple, Type, overload import httpx @@ -61,28 +62,22 @@ def make_batch_request_unparsed(self, reqs: Tuple[Body, ...]) -> str: return _after_request_unparsed(raw_response) @overload - def make_batch_request(self, reqs: _BodiesTup, parsers: _Tup) -> _RespTup: - ... + def make_batch_request(self, reqs: _BodiesTup, parsers: _Tup) -> _RespTup: ... @overload - def make_batch_request(self, reqs: _BodiesTup1, parsers: _Tup1) -> _RespTup1: - ... + def make_batch_request(self, reqs: _BodiesTup1, parsers: _Tup1) -> _RespTup1: ... @overload - def make_batch_request(self, reqs: _BodiesTup2, parsers: _Tup2) -> _RespTup2: - ... + def make_batch_request(self, reqs: _BodiesTup2, parsers: _Tup2) -> _RespTup2: ... @overload - def make_batch_request(self, reqs: _BodiesTup3, parsers: _Tup3) -> _RespTup3: - ... + def make_batch_request(self, reqs: _BodiesTup3, parsers: _Tup3) -> _RespTup3: ... @overload - def make_batch_request(self, reqs: _BodiesTup4, parsers: _Tup4) -> _RespTup4: - ... + def make_batch_request(self, reqs: _BodiesTup4, parsers: _Tup4) -> _RespTup4: ... @overload - def make_batch_request(self, reqs: _BodiesTup5, parsers: _Tup5) -> _RespTup5: - ... + def make_batch_request(self, reqs: _BodiesTup5, parsers: _Tup5) -> _RespTup5: ... def make_batch_request(self, reqs: Tuple[Body, ...], parsers: _Tuples) -> Tuple[RPCResult, ...]: """Make a HTTP batch request to an http rpc endpoint. diff --git a/src/solana/rpc/types.py b/src/solana/rpc/types.py index 17e834e9..2a898571 100644 --- a/src/solana/rpc/types.py +++ b/src/solana/rpc/types.py @@ -1,4 +1,5 @@ """RPC types.""" + from typing import NamedTuple, NewType, Optional from solders.pubkey import Pubkey @@ -36,7 +37,7 @@ class MemcmpOpts(NamedTuple): offset: int """Offset into program account data to start comparison: .""" - bytes: str # noqa: A003 + bytes: str """Data to match, as base-58 encoded string: .""" diff --git a/src/solana/transaction.py b/src/solana/transaction.py index a4d11bb2..eec75510 100644 --- a/src/solana/transaction.py +++ b/src/solana/transaction.py @@ -1,4 +1,5 @@ """Library to package an atomic sequence of instructions to a transaction.""" + from __future__ import annotations from typing import Any, List, NamedTuple, Optional, Sequence, Tuple, Union @@ -91,6 +92,7 @@ def __init__( """Transaction is deprecated and will be removed in a later release. Please use the Transaction module from solders.transaction instead.""", DeprecationWarning, + stacklevel=1, ) self._solders = _build_solders_tx( @@ -134,7 +136,7 @@ def recent_blockhash(self) -> Optional[Blockhash]: return self._solders.message.recent_blockhash @recent_blockhash.setter - def recent_blockhash(self, blockhash: Optional[Blockhash]) -> None: # noqa: D102 + def recent_blockhash(self, blockhash: Optional[Blockhash]) -> None: self._solders = _build_solders_tx( recent_blockhash=blockhash, nonce_info=None, @@ -149,7 +151,7 @@ def fee_payer(self) -> Optional[Pubkey]: return account_keys[0] if account_keys else None @fee_payer.setter - def fee_payer(self, payer: Optional[Pubkey]) -> None: # noqa: D102 + def fee_payer(self, payer: Optional[Pubkey]) -> None: self._solders = _build_solders_tx( recent_blockhash=self.recent_blockhash, nonce_info=None, @@ -164,7 +166,7 @@ def instructions(self) -> Tuple[Instruction, ...]: return tuple(_decompile_instructions(msg)) @instructions.setter - def instructions(self, ixns: Sequence[Instruction]) -> None: # noqa: D102 + def instructions(self, ixns: Sequence[Instruction]) -> None: self._solders = _build_solders_tx( recent_blockhash=self.recent_blockhash, nonce_info=None, diff --git a/src/solana/utils/security_txt.py b/src/solana/utils/security_txt.py index 6c226364..7f8ef81d 100644 --- a/src/solana/utils/security_txt.py +++ b/src/solana/utils/security_txt.py @@ -1,6 +1,5 @@ """Utils for security.txt.""" - from dataclasses import dataclass, fields from typing import Any, List, Optional diff --git a/src/solana/utils/validate.py b/src/solana/utils/validate.py index ee83c584..0f0ab4f6 100644 --- a/src/solana/utils/validate.py +++ b/src/solana/utils/validate.py @@ -1,4 +1,5 @@ """Validation utilities.""" + from __future__ import annotations from enum import IntEnum diff --git a/src/solana/vote_program.py b/src/solana/vote_program.py index cd661a98..e728ac62 100644 --- a/src/solana/vote_program.py +++ b/src/solana/vote_program.py @@ -1,4 +1,5 @@ """Library to interface with the vote program.""" + from __future__ import annotations from typing import NamedTuple @@ -9,6 +10,7 @@ from solana.constants import VOTE_PROGRAM_ID from solana._layouts.vote_instructions import VOTE_INSTRUCTIONS_LAYOUT, InstructionType + # Instrection Params class WithdrawFromVoteAccountParams(NamedTuple): """Transfer SOL from vote account to identity.""" diff --git a/src/spl/memo/constants.py b/src/spl/memo/constants.py index 07f41cc8..23c65edd 100644 --- a/src/spl/memo/constants.py +++ b/src/spl/memo/constants.py @@ -1,4 +1,5 @@ """Memo program constants.""" + from solders.pubkey import Pubkey MEMO_PROGRAM_ID: Pubkey = Pubkey.from_string("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr") diff --git a/src/spl/memo/instructions.py b/src/spl/memo/instructions.py index 8313804f..eebefc59 100644 --- a/src/spl/memo/instructions.py +++ b/src/spl/memo/instructions.py @@ -1,4 +1,5 @@ """Memo program instructions.""" + from __future__ import annotations from typing import NamedTuple diff --git a/src/spl/token/_layouts.py b/src/spl/token/_layouts.py index f9228f17..7dcc1269 100644 --- a/src/spl/token/_layouts.py +++ b/src/spl/token/_layouts.py @@ -1,4 +1,5 @@ """Token instruction layouts.""" + from enum import IntEnum from construct import Bytes, Int8ul, Int32ul, Int64ul, Pass, Switch diff --git a/src/spl/token/async_client.py b/src/spl/token/async_client.py index 1ec09626..3431a93a 100644 --- a/src/spl/token/async_client.py +++ b/src/spl/token/async_client.py @@ -1,5 +1,6 @@ # pylint: disable=too-many-arguments """Async SPL Token program client.""" + from __future__ import annotations from typing import List, Optional, Union, cast @@ -319,7 +320,13 @@ async def create_wrapped_native_account( recent_blockhash_to_use = ( (await conn.get_latest_blockhash()).value.blockhash if recent_blockhash is None else recent_blockhash ) - (new_account_public_key, txn, payer, new_account, opts,) = _TokenCore._create_wrapped_native_account_args( + ( + new_account_public_key, + txn, + payer, + new_account, + opts, + ) = _TokenCore._create_wrapped_native_account_args( program_id, owner, payer, diff --git a/src/spl/token/client.py b/src/spl/token/client.py index 6b372587..82f74d1b 100644 --- a/src/spl/token/client.py +++ b/src/spl/token/client.py @@ -1,5 +1,6 @@ # pylint: disable=too-many-arguments """SPL Token program client.""" + from __future__ import annotations from typing import List, Optional, Union, cast @@ -318,7 +319,13 @@ def create_wrapped_native_account( recent_blockhash_to_use = ( conn.get_latest_blockhash().value.blockhash if recent_blockhash is None else recent_blockhash ) - (new_account_public_key, txn, payer, new_account, opts,) = _TokenCore._create_wrapped_native_account_args( + ( + new_account_public_key, + txn, + payer, + new_account, + opts, + ) = _TokenCore._create_wrapped_native_account_args( program_id, owner, payer, diff --git a/src/spl/token/core.py b/src/spl/token/core.py index a4ebd81c..046c45cd 100644 --- a/src/spl/token/core.py +++ b/src/spl/token/core.py @@ -1,5 +1,6 @@ # pylint: disable=too-many-arguments """Helper code for client.py and async_client.py.""" + from __future__ import annotations from typing import TYPE_CHECKING, List, NamedTuple, Optional, Tuple, Type, Union @@ -75,7 +76,6 @@ class MintInfo(NamedTuple): class _TokenCore: # pylint: disable=too-few-public-methods - pubkey: Pubkey """The public key identifying this mint.""" @@ -190,7 +190,6 @@ def _create_account_args( def _create_associated_token_account_args( self, owner: Pubkey, skip_confirmation: bool, commitment: Commitment, recent_blockhash: Blockhash ) -> Tuple[Pubkey, Transaction, Keypair, TxOpts]: - # Construct transaction ix = spl_token.create_associated_token_account(payer=self.payer.pubkey(), owner=owner, mint=self.pubkey) msg = Message.new_with_blockhash([ix], self.payer.pubkey(), recent_blockhash) @@ -398,7 +397,7 @@ def _create_account_info(self, info: GetAccountInfoResp) -> AccountInfo: delegated_amount = decoded_data.delegated_amount is_initialized = decoded_data.state != 0 - is_frozen = decoded_data.state == 2 + is_frozen = decoded_data.state == 2 # noqa: PLR2004 if decoded_data.is_native_option == 1: rent_exempt_reserve = decoded_data.is_native diff --git a/tests/conftest.py b/tests/conftest.py index 6cdd699d..38bd8901 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ """Fixtures for pytest.""" + import asyncio import time from typing import NamedTuple @@ -131,7 +132,9 @@ def test_http_client(docker_services, _sleep_for_first_blocks) -> Client: # pyl @pytest.mark.integration @pytest.fixture(scope="session") def test_http_client_async( - docker_services, event_loop, _sleep_for_first_blocks # pylint: disable=redefined-outer-name + docker_services, + event_loop, + _sleep_for_first_blocks, # pylint: disable=redefined-outer-name ) -> AsyncClient: """Test http_client.is_connected.""" http_client = AsyncClient(commitment=Processed) diff --git a/tests/integration/test_async_http_client.py b/tests/integration/test_async_http_client.py index 6c04ac5a..d30598cb 100644 --- a/tests/integration/test_async_http_client.py +++ b/tests/integration/test_async_http_client.py @@ -1,4 +1,5 @@ """Tests for the HTTP API Client.""" + from typing import Tuple import pytest diff --git a/tests/integration/test_async_token_client.py b/tests/integration/test_async_token_client.py index 02a41c95..4b7fb7be 100644 --- a/tests/integration/test_async_token_client.py +++ b/tests/integration/test_async_token_client.py @@ -1,5 +1,6 @@ # pylint: disable=R0401 """Tests for the SPL Token Client.""" + import pytest import spl.token._layouts as layouts from solders.pubkey import Pubkey @@ -54,7 +55,8 @@ async def stubbed_sender_token_account_pk(stubbed_sender, test_token) -> Pubkey: @pytest.mark.integration @pytest.fixture(scope="module") async def async_stubbed_receiver_token_account_pk( - async_stubbed_receiver, test_token # pylint: disable=redefined-outer-name + async_stubbed_receiver, + test_token, # pylint: disable=redefined-outer-name ) -> Pubkey: """Token account for stubbed receiver.""" return await test_token.create_account(async_stubbed_receiver) @@ -95,9 +97,7 @@ async def test_new_associated_account(test_token): # pylint: disable=redefined- @pytest.mark.integration -async def test_get_account_info( - stubbed_sender, stubbed_sender_token_account_pk, test_token -): # pylint: disable=redefined-outer-name +async def test_get_account_info(stubbed_sender, stubbed_sender_token_account_pk, test_token): # pylint: disable=redefined-outer-name """Test get token account info.""" account_info = await test_token.get_account_info(stubbed_sender_token_account_pk) assert account_info.is_initialized is True @@ -124,9 +124,7 @@ async def test_get_mint_info(stubbed_sender, freeze_authority, test_token): # p @pytest.mark.integration -async def test_mint_to( - stubbed_sender, stubbed_sender_token_account_pk, test_token -): # pylint: disable=redefined-outer-name +async def test_mint_to(stubbed_sender, stubbed_sender_token_account_pk, test_token): # pylint: disable=redefined-outer-name """Test mint token to account and get balance.""" expected_amount = 1000 resp = await test_token.mint_to( @@ -165,9 +163,7 @@ async def test_transfer( @pytest.mark.integration -async def test_burn( - stubbed_sender, stubbed_sender_token_account_pk, test_token -): # pylint: disable=redefined-outer-name +async def test_burn(stubbed_sender, stubbed_sender_token_account_pk, test_token): # pylint: disable=redefined-outer-name """Test burning tokens.""" burn_amount = 200 expected_amount = 300 @@ -244,9 +240,7 @@ async def test_transfer_checked( @pytest.mark.integration -async def test_burn_checked( - stubbed_sender, stubbed_sender_token_account_pk, test_token -): # pylint: disable=redefined-outer-name +async def test_burn_checked(stubbed_sender, stubbed_sender_token_account_pk, test_token): # pylint: disable=redefined-outer-name """Test burning tokens checked.""" burn_amount = 500 expected_decimals = 6 @@ -354,9 +348,7 @@ async def test_approve_checked( @pytest.mark.integration -async def test_freeze_account( - stubbed_sender_token_account_pk, freeze_authority, test_token, test_http_client_async -): # pylint: disable=redefined-outer-name +async def test_freeze_account(stubbed_sender_token_account_pk, freeze_authority, test_token, test_http_client_async): # pylint: disable=redefined-outer-name """Test freezing an account.""" resp = await test_http_client_async.request_airdrop(freeze_authority.pubkey(), AIRDROP_AMOUNT) await test_http_client_async.confirm_transaction(resp.value) @@ -373,9 +365,7 @@ async def test_freeze_account( @pytest.mark.integration -async def test_thaw_account( - stubbed_sender_token_account_pk, freeze_authority, test_token, test_http_client_async -): # pylint: disable=redefined-outer-name +async def test_thaw_account(stubbed_sender_token_account_pk, freeze_authority, test_token, test_http_client_async): # pylint: disable=redefined-outer-name """Test thawing an account.""" account_info = await test_token.get_account_info(stubbed_sender_token_account_pk) assert account_info.is_frozen is True @@ -415,9 +405,7 @@ async def test_close_account( @pytest.mark.integration -async def test_create_multisig( - stubbed_sender, async_stubbed_receiver, test_token, test_http_client -): # pylint: disable=redefined-outer-name +async def test_create_multisig(stubbed_sender, async_stubbed_receiver, test_token, test_http_client): # pylint: disable=redefined-outer-name """Test creating a multisig account.""" min_signers = 2 multisig_pubkey = await test_token.create_multisig( diff --git a/tests/integration/test_http_client.py b/tests/integration/test_http_client.py index a9df5603..a26c8d0b 100644 --- a/tests/integration/test_http_client.py +++ b/tests/integration/test_http_client.py @@ -1,4 +1,5 @@ """Tests for the HTTP API Client.""" + from typing import Tuple import pytest @@ -530,10 +531,10 @@ def test_batch_request(test_http_client: Client): """Test get vote accounts.""" reqs = (GetBlockHeight(), GetFirstAvailableBlock()) parsers = (GetBlockHeightResp, GetFirstAvailableBlockResp) - resp: Tuple[ - Resp[GetBlockHeightResp], Resp[GetFirstAvailableBlockResp] - ] = test_http_client._provider.make_batch_request( # pylint: disable=protected-access - reqs, parsers + resp: Tuple[Resp[GetBlockHeightResp], Resp[GetFirstAvailableBlockResp]] = ( + test_http_client._provider.make_batch_request( # pylint: disable=protected-access + reqs, parsers + ) ) assert_valid_response(resp[0]) assert_valid_response(resp[1]) diff --git a/tests/integration/test_memo.py b/tests/integration/test_memo.py index 2eabbc77..c9849618 100644 --- a/tests/integration/test_memo.py +++ b/tests/integration/test_memo.py @@ -1,4 +1,5 @@ """Tests for the Memo program.""" + import pytest from solders.keypair import Keypair from solders.message import Message diff --git a/tests/integration/test_token_client.py b/tests/integration/test_token_client.py index 3a3852af..c61fbad5 100644 --- a/tests/integration/test_token_client.py +++ b/tests/integration/test_token_client.py @@ -1,5 +1,6 @@ # pylint: disable=R0401 """Tests for the SPL Token Client.""" + import pytest import spl.token._layouts as layouts from solders.pubkey import Pubkey @@ -93,9 +94,7 @@ def test_new_associated_account(test_token): # pylint: disable=redefined-outer- @pytest.mark.integration -def test_get_account_info( - stubbed_sender, stubbed_sender_token_account_pk, test_token -): # pylint: disable=redefined-outer-name +def test_get_account_info(stubbed_sender, stubbed_sender_token_account_pk, test_token): # pylint: disable=redefined-outer-name """Test get token account info.""" account_info = test_token.get_account_info(stubbed_sender_token_account_pk) assert account_info.is_initialized is True @@ -136,9 +135,7 @@ def test_mint_to(stubbed_sender, stubbed_sender_token_account_pk, test_token): @pytest.mark.integration -def test_transfer( - stubbed_sender, stubbed_receiver_token_account_pk, stubbed_sender_token_account_pk, test_token -): # pylint: disable=redefined-outer-name +def test_transfer(stubbed_sender, stubbed_receiver_token_account_pk, stubbed_sender_token_account_pk, test_token): # pylint: disable=redefined-outer-name """Test token transfer.""" expected_amount = 500 assert_valid_response( @@ -184,9 +181,7 @@ def test_burn( @pytest.mark.integration -def test_mint_to_checked( - stubbed_sender, stubbed_sender_token_account_pk, test_token -): # pylint: disable=redefined-outer-name +def test_mint_to_checked(stubbed_sender, stubbed_sender_token_account_pk, test_token): # pylint: disable=redefined-outer-name """Test mint token checked and get balance.""" expected_amount = 1000 mint_amount = 700 @@ -237,9 +232,7 @@ def test_transfer_checked( @pytest.mark.integration -def test_burn_checked( - stubbed_sender, stubbed_sender_token_account_pk, test_token -): # pylint: disable=redefined-outer-name +def test_burn_checked(stubbed_sender, stubbed_sender_token_account_pk, test_token): # pylint: disable=redefined-outer-name """Test burning tokens checked.""" burn_amount = 500 expected_decimals = 6 @@ -274,9 +267,7 @@ def test_get_accounts(stubbed_sender, test_token): # pylint: disable=redefined- @pytest.mark.integration -def test_approve( - stubbed_sender, stubbed_receiver, stubbed_sender_token_account_pk, test_token, test_http_client -): # pylint: disable=redefined-outer-name +def test_approve(stubbed_sender, stubbed_receiver, stubbed_sender_token_account_pk, test_token, test_http_client): # pylint: disable=redefined-outer-name """Test approval for delegating a token account.""" expected_amount_delegated = 500 resp = test_token.approve( @@ -296,9 +287,7 @@ def test_approve( @pytest.mark.integration -def test_revoke( - stubbed_sender, stubbed_receiver, stubbed_sender_token_account_pk, test_token, test_http_client -): # pylint: disable=redefined-outer-name +def test_revoke(stubbed_sender, stubbed_receiver, stubbed_sender_token_account_pk, test_token, test_http_client): # pylint: disable=redefined-outer-name """Test revoke for undelegating a token account.""" expected_amount_delegated = 500 account_info = test_token.get_account_info(stubbed_sender_token_account_pk) @@ -337,9 +326,7 @@ def test_approve_checked( @pytest.mark.integration -def test_freeze_account( - stubbed_sender_token_account_pk, freeze_authority, test_token, test_http_client -): # pylint: disable=redefined-outer-name +def test_freeze_account(stubbed_sender_token_account_pk, freeze_authority, test_token, test_http_client): # pylint: disable=redefined-outer-name """Test freezing an account.""" resp = test_http_client.request_airdrop(freeze_authority.pubkey(), AIRDROP_AMOUNT) assert_valid_response(resp) @@ -358,9 +345,7 @@ def test_freeze_account( @pytest.mark.integration -def test_thaw_account( - stubbed_sender_token_account_pk, freeze_authority, test_token, test_http_client -): # pylint: disable=redefined-outer-name +def test_thaw_account(stubbed_sender_token_account_pk, freeze_authority, test_token, test_http_client): # pylint: disable=redefined-outer-name """Test thawing an account.""" account_info = test_token.get_account_info(stubbed_sender_token_account_pk) assert account_info.is_frozen is True @@ -399,9 +384,7 @@ def test_close_account( @pytest.mark.integration -def test_create_multisig( - stubbed_sender, stubbed_receiver, test_token, test_http_client -): # pylint: disable=redefined-outer-name +def test_create_multisig(stubbed_sender, stubbed_receiver, test_token, test_http_client): # pylint: disable=redefined-outer-name """Test creating a multisig account.""" min_signers = 2 multisig_pubkey = test_token.create_multisig(min_signers, [stubbed_sender.pubkey(), stubbed_receiver], opts=OPTS) diff --git a/tests/integration/test_websockets.py b/tests/integration/test_websockets.py index db8bf7f0..bd39010a 100644 --- a/tests/integration/test_websockets.py +++ b/tests/integration/test_websockets.py @@ -1,5 +1,6 @@ # pylint: disable=unused-argument,redefined-outer-name """Tests for the Websocket Client.""" + from typing import AsyncGenerator, List, Tuple import asyncstdlib @@ -210,9 +211,7 @@ async def test_multiple_subscriptions( await test_http_client_async.request_airdrop(stubbed_sender.pubkey(), AIRDROP_AMOUNT) async for idx, message in asyncstdlib.enumerate(websocket): for item in message: - if isinstance(item, AccountNotification): - assert item.result is not None - elif isinstance(item, LogsNotification): + if isinstance(item, (AccountNotification, LogsNotification)): assert item.result is not None else: raise ValueError(f"Unexpected message for this test: {item}") diff --git a/tests/unit/test_async_client.py b/tests/unit/test_async_client.py index d299b3b0..a871dc45 100644 --- a/tests/unit/test_async_client.py +++ b/tests/unit/test_async_client.py @@ -1,4 +1,5 @@ """Test async client.""" + from unittest.mock import patch import pytest diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index 02d02f37..8a9569e3 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -1,4 +1,5 @@ """Test sync client.""" + from unittest.mock import patch import pytest diff --git a/tests/unit/test_legacy_transaction.py b/tests/unit/test_legacy_transaction.py index 17bb82fa..2e24b9a1 100644 --- a/tests/unit/test_legacy_transaction.py +++ b/tests/unit/test_legacy_transaction.py @@ -1,4 +1,5 @@ """Unit tests for solana.transaction.""" + from base64 import b64decode, b64encode import pytest diff --git a/tests/unit/test_spl_token_instructions.py b/tests/unit/test_spl_token_instructions.py index cc97436f..be9936d2 100644 --- a/tests/unit/test_spl_token_instructions.py +++ b/tests/unit/test_spl_token_instructions.py @@ -1,4 +1,5 @@ """Unit tests for SPL-token instructions.""" + import spl.token.instructions as spl_token from solders.pubkey import Pubkey from solders.system_program import ID as SYSTEM_PROGRAM_ID diff --git a/tests/unit/test_vote_program.py b/tests/unit/test_vote_program.py index f24a3ad3..9732f89d 100644 --- a/tests/unit/test_vote_program.py +++ b/tests/unit/test_vote_program.py @@ -1,4 +1,5 @@ """Unit tests for solana.vote_program.""" + import base64 from solders.hash import Hash @@ -102,10 +103,10 @@ def test_withdraw_from_vote_account(): # --blockhash Add1tV7kJgNHhTtx3Dgs6dhC7kyXrGJQZ2tJGW15tLDH \ # --sign-only -k withdrawer.json cli_wire_msg = base64.b64decode( # noqa: F841 - b"AQABBDqF5SfUR/5I9i2gnIHHEr01j2JItmpFHSaRd74NaZ1wqxUGDtH5ah3TqEKWjcTmfHkpZC1h57NJL8Sx7Q6Olm2F2O70oOvzt1HgIVu+nySaSrWtJiK1eDacPPDWRxCwFgdhSB01dHS7fE12JOvTvbPYNV5z0RBD/A2jU4AAAAAAjxrQaMS7FjmaR++mvFr3XE6XbzMUTMJUIpITrUWBzGwBAwMBAgAMAwAAAACUNXcAAAAA" # noqa: E501 pylint: disable=line-too-long + b"AQABBDqF5SfUR/5I9i2gnIHHEr01j2JItmpFHSaRd74NaZ1wqxUGDtH5ah3TqEKWjcTmfHkpZC1h57NJL8Sx7Q6Olm2F2O70oOvzt1HgIVu+nySaSrWtJiK1eDacPPDWRxCwFgdhSB01dHS7fE12JOvTvbPYNV5z0RBD/A2jU4AAAAAAjxrQaMS7FjmaR++mvFr3XE6XbzMUTMJUIpITrUWBzGwBAwMBAgAMAwAAAACUNXcAAAAA" ) js_wire_msg = base64.b64decode( - b"AQABBDqF5SfUR/5I9i2gnIHHEr01j2JItmpFHSaRd74NaZ1whdju9KDr87dR4CFbvp8kmkq1rSYitXg2nDzw1kcQsBarFQYO0flqHdOoQpaNxOZ8eSlkLWHns0kvxLHtDo6WbQdhSB01dHS7fE12JOvTvbPYNV5z0RBD/A2jU4AAAAAAjxrQaMS7FjmaR++mvFr3XE6XbzMUTMJUIpITrUWBzGwBAwMCAQAMAwAAAACUNXcAAAAA" # noqa: E501 pylint: disable=line-too-long + b"AQABBDqF5SfUR/5I9i2gnIHHEr01j2JItmpFHSaRd74NaZ1whdju9KDr87dR4CFbvp8kmkq1rSYitXg2nDzw1kcQsBarFQYO0flqHdOoQpaNxOZ8eSlkLWHns0kvxLHtDo6WbQdhSB01dHS7fE12JOvTvbPYNV5z0RBD/A2jU4AAAAAAjxrQaMS7FjmaR++mvFr3XE6XbzMUTMJUIpITrUWBzGwBAwMCAQAMAwAAAACUNXcAAAAA" ) serialized_message = bytes(msg) diff --git a/tests/utils.py b/tests/utils.py index ab439a3d..6c65e954 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,4 +1,5 @@ """Integration test utils.""" + from typing import get_args from solders.rpc.responses import RPCError, RPCResult