From a21358fc40123d7182af52ec793fe71df92ff676 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 17 Sep 2024 18:29:27 -0400 Subject: [PATCH 01/11] update lockfile --- poetry.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index a5562245c..4ec7cd398 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.5.1 and should not be changed by hand. [[package]] name = "aiounittest" @@ -1368,4 +1368,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "b3ba481a29769ea03fe6430853c9409f2bce61f3dd30ab9a872c63ab8443072c" +content-hash = "c837b69fc72659241ad998e7bfe2a0aff8d91e01701aa09b8b2e74a2086075a4" From f5c328c02ce483a1a2f98a9d406a1b998466698c Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 17 Sep 2024 18:38:50 -0400 Subject: [PATCH 02/11] update flake8 --- .github/workflows/unit_test.yml | 2 +- CONTRIBUTING.md | 2 +- poetry.lock | 36 ++++++++++++++++----------------- pyproject.toml | 5 +++-- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index b1c8ce2fa..d9e387e8f 100644 --- a/.github/workflows/unit_test.yml +++ b/.github/workflows/unit_test.yml @@ -49,7 +49,7 @@ jobs: - name: Lint run: | - poetry run flake8 xrpl tests snippets --darglint-ignore-regex="^_(.*)" + poetry run poe lint - name: Type-check run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af34609b7..a67b7624f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,7 +66,7 @@ To run linting and other checks, `xrpl-py` uses [`pre-commit`](https://pre-commi To run the linter: ```bash -poetry run flake8 xrpl tests --darglint-ignore-regex="^_(.*)" +poetry run poe lint ``` ### Running Tests diff --git a/poetry.lock b/poetry.lock index 4ec7cd398..86712ed23 100644 --- a/poetry.lock +++ b/poetry.lock @@ -412,19 +412,19 @@ test = ["pytest (>=6)"] [[package]] name = "flake8" -version = "3.9.2" +version = "4.0.1" description = "the modular source code checker: pep8 pyflakes and co" optional = false -python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" +python-versions = ">=3.6" files = [ - {file = "flake8-3.9.2-py2.py3-none-any.whl", hash = "sha256:bf8fd333346d844f616e8d47905ef3a3384edae6b4e9beb0c5101e25e3110907"}, - {file = "flake8-3.9.2.tar.gz", hash = "sha256:07528381786f2a6237b061f6e96610a4167b226cb926e2aa2b6b1d78057c576b"}, + {file = "flake8-4.0.1-py2.py3-none-any.whl", hash = "sha256:479b1304f72536a55948cb40a32dce8bb0ffe3501e26eaf292c7e60eb5e0428d"}, + {file = "flake8-4.0.1.tar.gz", hash = "sha256:806e034dda44114815e23c16ef92f95c91e4c71100ff52813adf7132a6ad870d"}, ] [package.dependencies] mccabe = ">=0.6.0,<0.7.0" -pycodestyle = ">=2.7.0,<2.8.0" -pyflakes = ">=2.3.0,<2.4.0" +pycodestyle = ">=2.8.0,<2.9.0" +pyflakes = ">=2.4.0,<2.5.0" [[package]] name = "flake8-absolute-import" @@ -821,13 +821,13 @@ type = ["mypy (>=1.8)"] [[package]] name = "poethepoet" -version = "0.19.0" +version = "0.24.4" description = "A task runner that works well with poetry." optional = false -python-versions = ">=3.7" +python-versions = ">=3.8" files = [ - {file = "poethepoet-0.19.0-py3-none-any.whl", hash = "sha256:87038be589077e4b407050a9da644d9cd9e4076ccfc8abc7f855cf6870d5c6c2"}, - {file = "poethepoet-0.19.0.tar.gz", hash = "sha256:897eb85ec15876d79befc7d19d4c80ce7c8b214d1bb0dcfec640abd81616bfed"}, + {file = "poethepoet-0.24.4-py3-none-any.whl", hash = "sha256:fb4ea35d7f40fe2081ea917d2e4102e2310fda2cde78974050ca83896e229075"}, + {file = "poethepoet-0.24.4.tar.gz", hash = "sha256:ff4220843a87c888cbcb5312c8905214701d0af60ac7271795baa8369b428fef"}, ] [package.dependencies] @@ -839,13 +839,13 @@ poetry-plugin = ["poetry (>=1.0,<2.0)"] [[package]] name = "pycodestyle" -version = "2.7.0" +version = "2.8.0" description = "Python style guide checker" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" files = [ - {file = "pycodestyle-2.7.0-py2.py3-none-any.whl", hash = "sha256:514f76d918fcc0b55c6680472f0a37970994e07bbb80725808c17089be302068"}, - {file = "pycodestyle-2.7.0.tar.gz", hash = "sha256:c389c1d06bf7904078ca03399a4816f974a1d590090fecea0c63ec26ebaf1cef"}, + {file = "pycodestyle-2.8.0-py2.py3-none-any.whl", hash = "sha256:720f8b39dde8b293825e7ff02c475f3077124006db4f440dcbc9a20b76548a20"}, + {file = "pycodestyle-2.8.0.tar.gz", hash = "sha256:eddd5847ef438ea1c7870ca7eb78a9d47ce0cdb4851a5523949f2601d0cbbe7f"}, ] [[package]] @@ -908,13 +908,13 @@ toml = ["tomli (>=1.2.3)"] [[package]] name = "pyflakes" -version = "2.3.1" +version = "2.4.0" description = "passive checker of Python programs" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" files = [ - {file = "pyflakes-2.3.1-py2.py3-none-any.whl", hash = "sha256:7893783d01b8a89811dd72d7dfd4d84ff098e5eed95cfa8905b22bbffe52efc3"}, - {file = "pyflakes-2.3.1.tar.gz", hash = "sha256:f5bc8ecabc05bb9d291eb5203d6810b49040f6ff446a756326104746cc00c1db"}, + {file = "pyflakes-2.4.0-py2.py3-none-any.whl", hash = "sha256:3bb3a3f256f4b7968c9c788781e4ff07dce46bdf12339dcda61053375426ee2e"}, + {file = "pyflakes-2.4.0.tar.gz", hash = "sha256:05a85c2872edf37a4ed30b0cce2f6093e1d0581f8c19d7393122da7e25b2b24c"}, ] [[package]] @@ -1368,4 +1368,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "c837b69fc72659241ad998e7bfe2a0aff8d91e01701aa09b8b2e74a2086075a4" +content-hash = "ff536fb63a0e5935eac64b686c86462ce31f49e34e610ffa2b8e3916fcaeed74" diff --git a/pyproject.toml b/pyproject.toml index b18f07915..38735ae96 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ types-Deprecated = "^1.2.9" pycryptodome = "^3.16.0" [tool.poetry.dev-dependencies] -flake8 = "^3.8.4" +flake8 = "^4.0.0" black = "23.3.0" flake8-black = "^0.3.6" flake8-docstrings = "^1.7.0" @@ -57,7 +57,7 @@ coverage = "^7.2.7" Jinja2 = "^3.1.4" MarkupSafe = "2.1.5" Sphinx = "^5.3.0" -poethepoet = "^0.19.0" +poethepoet = "^0.24.0" [tool.isort] # Make sure that isort's settings line up with black @@ -80,6 +80,7 @@ precision = 2 [tool.poe.tasks] test_unit = "coverage run -m unittest discover tests/unit" test_integration = "coverage run -m unittest discover tests/integration" +lint = "poetry run flake8 xrpl tests snippets --darglint-ignore-regex=\"^_(.*)\"" [tool.poe.tasks.test] cmd = "python3 -m unittest ${FILE_PATHS}" From d74bf350cd9d7b3adabb155cca6c9d4beb1e3ba9 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 17 Sep 2024 18:48:31 -0400 Subject: [PATCH 03/11] upgrade flake8, fix linter errors --- poetry.lock | 72 ++++++++++++------- pyproject.toml | 6 +- .../binarycodec/types/test_serialized_type.py | 2 +- xrpl/core/addresscodec/codec.py | 4 +- .../core/binarycodec/types/serialized_type.py | 6 +- xrpl/core/binarycodec/types/st_object.py | 10 +-- xrpl/models/base_model.py | 6 +- xrpl/models/nested_model.py | 2 +- xrpl/models/requests/generic_request.py | 2 +- xrpl/models/response.py | 4 +- xrpl/utils/xrp_conversions.py | 5 +- 11 files changed, 70 insertions(+), 49 deletions(-) diff --git a/poetry.lock b/poetry.lock index 86712ed23..e308083b5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -47,6 +47,25 @@ doc = ["Sphinx (>=7)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)", "sphin test = ["anyio[trio]", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", "hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "pytest-mock (>=3.6.1)", "trustme", "uvloop (>=0.17)"] trio = ["trio (>=0.23)"] +[[package]] +name = "attrs" +version = "24.2.0" +description = "Classes Without Boilerplate" +optional = false +python-versions = ">=3.7" +files = [ + {file = "attrs-24.2.0-py3-none-any.whl", hash = "sha256:81921eb96de3191c8258c199618104dd27ac608d9366f5e35d011eae1867ede2"}, + {file = "attrs-24.2.0.tar.gz", hash = "sha256:5cfb1b9148b5b086569baec03f20d7b6bf3bcacc9a42bebf87ffaaca362f6346"}, +] + +[package.extras] +benchmark = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-codspeed", "pytest-mypy-plugins", "pytest-xdist[psutil]"] +cov = ["cloudpickle", "coverage[toml] (>=5.3)", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] +dev = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pre-commit", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] +docs = ["cogapp", "furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier (<24.7)"] +tests = ["cloudpickle", "hypothesis", "mypy (>=1.11.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] +tests-mypy = ["mypy (>=1.11.1)", "pytest-mypy-plugins"] + [[package]] name = "babel" version = "2.16.0" @@ -412,19 +431,19 @@ test = ["pytest (>=6)"] [[package]] name = "flake8" -version = "4.0.1" +version = "7.1.1" description = "the modular source code checker: pep8 pyflakes and co" optional = false -python-versions = ">=3.6" +python-versions = ">=3.8.1" files = [ - {file = "flake8-4.0.1-py2.py3-none-any.whl", hash = "sha256:479b1304f72536a55948cb40a32dce8bb0ffe3501e26eaf292c7e60eb5e0428d"}, - {file = "flake8-4.0.1.tar.gz", hash = "sha256:806e034dda44114815e23c16ef92f95c91e4c71100ff52813adf7132a6ad870d"}, + {file = "flake8-7.1.1-py2.py3-none-any.whl", hash = "sha256:597477df7860daa5aa0fdd84bf5208a043ab96b8e96ab708770ae0364dd03213"}, + {file = "flake8-7.1.1.tar.gz", hash = "sha256:049d058491e228e03e67b390f311bbf88fce2dbaa8fa673e7aea87b7198b8d38"}, ] [package.dependencies] -mccabe = ">=0.6.0,<0.7.0" -pycodestyle = ">=2.8.0,<2.9.0" -pyflakes = ">=2.4.0,<2.5.0" +mccabe = ">=0.7.0,<0.8.0" +pycodestyle = ">=2.12.0,<2.13.0" +pyflakes = ">=3.2.0,<3.3.0" [[package]] name = "flake8-absolute-import" @@ -441,17 +460,18 @@ flake8 = ">=3.7" [[package]] name = "flake8-annotations" -version = "2.7.0" +version = "3.1.1" description = "Flake8 Type Annotation Checks" optional = false -python-versions = ">=3.6.2,<4.0.0" +python-versions = ">=3.8.1" files = [ - {file = "flake8-annotations-2.7.0.tar.gz", hash = "sha256:52e53c05b0c06cac1c2dec192ea2c36e85081238add3bd99421d56f574b9479b"}, - {file = "flake8_annotations-2.7.0-py3-none-any.whl", hash = "sha256:3edfbbfb58e404868834fe6ec3eaf49c139f64f0701259f707d043185545151e"}, + {file = "flake8_annotations-3.1.1-py3-none-any.whl", hash = "sha256:102935bdcbfa714759a152aeb07b14aee343fc0b6f7c55ad16968ce3e0e91a8a"}, + {file = "flake8_annotations-3.1.1.tar.gz", hash = "sha256:6c98968ccc6bdc0581d363bf147a87df2f01d0d078264b2da805799d911cf5fe"}, ] [package.dependencies] -flake8 = ">=3.7,<5.0" +attrs = ">=21.4" +flake8 = ">=5.0" [[package]] name = "flake8-black" @@ -703,13 +723,13 @@ files = [ [[package]] name = "mccabe" -version = "0.6.1" +version = "0.7.0" description = "McCabe checker, plugin for flake8" optional = false -python-versions = "*" +python-versions = ">=3.6" files = [ - {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, - {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, + {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, + {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, ] [[package]] @@ -839,13 +859,13 @@ poetry-plugin = ["poetry (>=1.0,<2.0)"] [[package]] name = "pycodestyle" -version = "2.8.0" +version = "2.12.1" description = "Python style guide checker" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +python-versions = ">=3.8" files = [ - {file = "pycodestyle-2.8.0-py2.py3-none-any.whl", hash = "sha256:720f8b39dde8b293825e7ff02c475f3077124006db4f440dcbc9a20b76548a20"}, - {file = "pycodestyle-2.8.0.tar.gz", hash = "sha256:eddd5847ef438ea1c7870ca7eb78a9d47ce0cdb4851a5523949f2601d0cbbe7f"}, + {file = "pycodestyle-2.12.1-py2.py3-none-any.whl", hash = "sha256:46f0fb92069a7c28ab7bb558f05bfc0110dac69a0cd23c61ea0040283a9d78b3"}, + {file = "pycodestyle-2.12.1.tar.gz", hash = "sha256:6838eae08bbce4f6accd5d5572075c63626a15ee3e6f842df996bf62f6d73521"}, ] [[package]] @@ -908,13 +928,13 @@ toml = ["tomli (>=1.2.3)"] [[package]] name = "pyflakes" -version = "2.4.0" +version = "3.2.0" description = "passive checker of Python programs" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=3.8" files = [ - {file = "pyflakes-2.4.0-py2.py3-none-any.whl", hash = "sha256:3bb3a3f256f4b7968c9c788781e4ff07dce46bdf12339dcda61053375426ee2e"}, - {file = "pyflakes-2.4.0.tar.gz", hash = "sha256:05a85c2872edf37a4ed30b0cce2f6093e1d0581f8c19d7393122da7e25b2b24c"}, + {file = "pyflakes-3.2.0-py2.py3-none-any.whl", hash = "sha256:84b5be138a2dfbb40689ca07e2152deb896a65c3a3e24c251c5c62489568074a"}, + {file = "pyflakes-3.2.0.tar.gz", hash = "sha256:1c61603ff154621fb2a9172037d84dca3500def8c8b630657d1701f026f8af3f"}, ] [[package]] @@ -1367,5 +1387,5 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" -python-versions = "^3.8" -content-hash = "ff536fb63a0e5935eac64b686c86462ce31f49e34e610ffa2b8e3916fcaeed74" +python-versions = "^3.8.1" +content-hash = "9d455f637b53b084cfaa245b00a4e9e25e1c161ddbf84803e85d1b090c47a3e3" diff --git a/pyproject.toml b/pyproject.toml index 38735ae96..b37bb6c45 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ packages = [ ] [tool.poetry.dependencies] -python = "^3.8" +python = "^3.8.1" base58 = "^2.1.0" ECPy = "^1.2.5" typing-extensions = "^4.2.0" @@ -41,14 +41,14 @@ types-Deprecated = "^1.2.9" pycryptodome = "^3.16.0" [tool.poetry.dev-dependencies] -flake8 = "^4.0.0" +flake8 = "^7.0.0" black = "23.3.0" flake8-black = "^0.3.6" flake8-docstrings = "^1.7.0" mypy = "^1" isort = "^5.11.5" flake8-isort = "^6.0.0" -flake8-annotations = "2.7.0" +flake8-annotations = "3.1.1" flake8-absolute-import = "^1.0" darglint = "^1.5.8" sphinx-rtd-theme = "^2.0.0" diff --git a/tests/unit/core/binarycodec/types/test_serialized_type.py b/tests/unit/core/binarycodec/types/test_serialized_type.py index 79e3ca1ba..3fa9d2acb 100644 --- a/tests/unit/core/binarycodec/types/test_serialized_type.py +++ b/tests/unit/core/binarycodec/types/test_serialized_type.py @@ -48,7 +48,7 @@ class TestSerializedType(TestCase): def fixture_test(self, fixture: ValueTest): """Run the appropriate test for given fixture case.""" serialized_type: SerializedType = TYPE_MAP[fixture.type] - if type(fixture.test_json) == dict: + if isinstance(fixture.test_json, dict): json_value = fixture.test_json else: json_value = str(fixture.test_json) diff --git a/xrpl/core/addresscodec/codec.py b/xrpl/core/addresscodec/codec.py index 479023acf..c64aa2c38 100644 --- a/xrpl/core/addresscodec/codec.py +++ b/xrpl/core/addresscodec/codec.py @@ -40,8 +40,8 @@ def _encode(bytestring: bytes, prefix: List[int], expected_length: int) -> str: length. """ if expected_length and len(bytestring) != expected_length: - error_message = """unexpected_payload_length: len(bytestring) does not match expected_length. - Ensure that the bytes are a bytestring.""" + error_message = """unexpected_payload_length: len(bytestring) does not match + expected_length. Ensure that the bytes are a bytestring.""" raise XRPLAddressCodecException(error_message) encoded_prefix = bytes(prefix) payload = encoded_prefix + bytestring diff --git a/xrpl/core/binarycodec/types/serialized_type.py b/xrpl/core/binarycodec/types/serialized_type.py index 4feb90a75..327ef6fcb 100644 --- a/xrpl/core/binarycodec/types/serialized_type.py +++ b/xrpl/core/binarycodec/types/serialized_type.py @@ -25,13 +25,13 @@ def from_parser( # noqa: D102 cls: Type[Self], parser: BinaryParser, # length_hint is Any so that subclasses can choose whether or not to require it. - length_hint: Any, + length_hint: Any, # noqa: ANN401 ) -> Self: pass @classmethod @abstractmethod - def from_value(cls: Type[Self], value: Any) -> Self: # noqa: D102 + def from_value(cls: Type[Self], value: Any) -> Self: # noqa: D102 ANN401 pass def to_byte_sink(self: Self, bytesink: bytearray) -> None: @@ -54,7 +54,7 @@ def __bytes__(self: Self) -> bytes: """ return self.buffer - def to_json(self: Self) -> Any: + def to_json(self: Self) -> Any: # noqa: ANN401 """ Returns the JSON representation of a SerializedType. diff --git a/xrpl/core/binarycodec/types/st_object.py b/xrpl/core/binarycodec/types/st_object.py index 272ce19e5..22412bd7d 100644 --- a/xrpl/core/binarycodec/types/st_object.py +++ b/xrpl/core/binarycodec/types/st_object.py @@ -58,9 +58,9 @@ def _handle_xaddress(field: str, xaddress: str) -> Dict[str, Union[str, int]]: return {field: classic_address} -def _str_to_enum(field: str, value: Any) -> Any: - # all of these fields have enum values that are used for serialization - # converts the string name to the corresponding enum code +# all of these fields have enum values that are used for serialization +# converts the string name to the corresponding enum code +def _str_to_enum(field: str, value: Any) -> Any: # noqa: ANN401 if field == "TransactionType": return get_transaction_type_code(value) if field == "TransactionResult": @@ -70,8 +70,8 @@ def _str_to_enum(field: str, value: Any) -> Any: return value -def _enum_to_str(field: str, value: Any) -> Any: - # reverse of the above function +# reverse of the above function +def _enum_to_str(field: str, value: Any) -> Any: # noqa: ANN401 if field == "TransactionType": return get_transaction_type_name(value) if field == "TransactionResult": diff --git a/xrpl/models/base_model.py b/xrpl/models/base_model.py index 84c0416fc..e12300f15 100644 --- a/xrpl/models/base_model.py +++ b/xrpl/models/base_model.py @@ -85,7 +85,7 @@ class BaseModel(ABC): """The base class for all model types.""" @classmethod - def is_dict_of_model(cls: Type[Self], dictionary: Any) -> bool: + def is_dict_of_model(cls: Type[Self], dictionary: Any) -> bool: # noqa: ANN401 """ Checks whether the provided ``dictionary`` is a dictionary representation of this class. @@ -150,7 +150,7 @@ def _from_dict_single_param( param: str, param_type: Type[Any], param_value: Union[int, str, bool, BaseModel, Enum, List[Any], Dict[str, Any]], - ) -> Any: + ) -> Any: # noqa: ANN401 """Recursively handles each individual param in `from_dict`.""" param_type_origin = get_origin(param_type) # returns `list` if a List, `Union` if a Union, None otherwise @@ -321,7 +321,7 @@ def to_dict(self: Self) -> Dict[str, Any]: if getattr(self, key) is not None } - def _to_dict_elem(self: Self, elem: Any) -> Any: + def _to_dict_elem(self: Self, elem: Any) -> Any: # noqa: ANN401 if isinstance(elem, BaseModel): return elem.to_dict() if isinstance(elem, Enum): diff --git a/xrpl/models/nested_model.py b/xrpl/models/nested_model.py index 96a400e5e..43f20d9ff 100644 --- a/xrpl/models/nested_model.py +++ b/xrpl/models/nested_model.py @@ -21,7 +21,7 @@ class NestedModel(BaseModel): """The base class for models that involve a nested dictionary e.g. memos.""" @classmethod - def is_dict_of_model(cls: Type[Self], dictionary: Any) -> bool: + def is_dict_of_model(cls: Type[Self], dictionary: Any) -> bool: # noqa: ANN401 """ Returns True if the input dictionary was derived by the `to_dict` method of an instance of this class. In other words, True if this is diff --git a/xrpl/models/requests/generic_request.py b/xrpl/models/requests/generic_request.py index d11b89244..f1c34fba2 100644 --- a/xrpl/models/requests/generic_request.py +++ b/xrpl/models/requests/generic_request.py @@ -28,7 +28,7 @@ class GenericRequest(Request): :meta hide-value: """ - def __init__(self: Self, **kwargs: Any) -> None: + def __init__(self: Self, **kwargs: Any) -> None: # noqa: ANN401 """ Initializes a GenericRequest. diff --git a/xrpl/models/response.py b/xrpl/models/response.py index 84e369a6f..fd24133b4 100644 --- a/xrpl/models/response.py +++ b/xrpl/models/response.py @@ -92,7 +92,7 @@ def contains_partial_payment(self: Self) -> bool: """ return self._do_contains_partial_payment(self.result) - def _do_contains_partial_payment(self: Self, val: Any) -> bool: + def _do_contains_partial_payment(self: Self, val: Any) -> bool: # noqa: ANN401 flagged = [] if isinstance(val, dict): formatted = {key.strip().lower(): value for key, value in val.items()} @@ -111,7 +111,7 @@ def _do_contains_partial_payment(self: Self, val: Any) -> bool: ] return len(flagged) > 0 - def _is_partial_payment(self: Self, key: str, val: Any) -> bool: + def _is_partial_payment(self: Self, key: str, val: Any) -> bool: # noqa: ANN401 if isinstance(val, dict): return self._do_contains_partial_payment(val) try: diff --git a/xrpl/utils/xrp_conversions.py b/xrpl/utils/xrp_conversions.py index d8aa2cf3c..884ca1a13 100644 --- a/xrpl/utils/xrp_conversions.py +++ b/xrpl/utils/xrp_conversions.py @@ -1,4 +1,5 @@ """Conversions between XRP drops and native number types.""" + import re from decimal import Decimal, InvalidOperation, localcontext from typing import Pattern, Union @@ -35,7 +36,7 @@ def xrp_to_drops(xrp: Union[int, float, Decimal]) -> str: TypeError: if ``xrp`` is given as a string XRPRangeException: if the given amount of XRP is invalid """ - if type(xrp) == str: # type: ignore + if isinstance(xrp, str): # This protects people from passing drops to this function and getting # a million times as many drops back. raise TypeError( @@ -83,7 +84,7 @@ def drops_to_xrp(drops: str) -> Decimal: TypeError: if ``drops`` not given as a string XRPRangeException: if the given number of drops is invalid """ - if type(drops) != str: + if isinstance(drops, str): raise TypeError(f"Drops must be provided as string (got {type(drops)})") drops = drops.strip() with localcontext(DROPS_DECIMAL_CONTEXT): From 5c257bbc18702aa5318b83ef22f1964330d407fd Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 17 Sep 2024 18:55:01 -0400 Subject: [PATCH 04/11] add pydoclint --- .flake8 | 9 ++++++++- poetry.lock | 32 +++++++++++++++++++++++++++++++- pyproject.toml | 3 ++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/.flake8 b/.flake8 index 87bd1ef41..c06aaa4ac 100644 --- a/.flake8 +++ b/.flake8 @@ -11,6 +11,11 @@ ignore = D205,D212,D415,E203,W503 # https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length max-line-length = 88 +# This is for pydocstyle - to allow docstrings in __init__ functions +# This rule was used for easier migration from darglint +# TODO: remove this rule +allow-init-docstring=True + per-file-ignores = # For tests, disable type annotation and docstring linting. tests/*: ANN D DAR @@ -27,6 +32,8 @@ per-file-ignores = # DAR enables docstring style linting via darglint. +# DIC enables docstring style linting via pydoclint. + # F are errors reported by pyflakes, a tool which parses source files # and finds invalid Python code. @@ -35,4 +42,4 @@ per-file-ignores = # W and E are warnings and errors reported by pycodestyle, which checks # your Python code against some of the style conventions in PEP 8. -select = ABS,ANN,DAR,BLK,D,E,F,I,W +select = ABS,ANN,DAR,DOC,BLK,D,E,F,I,W diff --git a/poetry.lock b/poetry.lock index e308083b5..c53131061 100644 --- a/poetry.lock +++ b/poetry.lock @@ -393,6 +393,17 @@ wrapt = ">=1.10,<2" [package.extras] dev = ["PyTest", "PyTest-Cov", "bump2version (<1)", "sphinx (<2)", "tox"] +[[package]] +name = "docstring-parser-fork" +version = "0.0.9" +description = "Parse Python docstrings in reST, Google and Numpydoc format" +optional = false +python-versions = "<4.0,>=3.7" +files = [ + {file = "docstring_parser_fork-0.0.9-py3-none-any.whl", hash = "sha256:0be85ad00cb25bf5beeb673e46e777facf0f47552fa3a7570d120ef7e3374401"}, + {file = "docstring_parser_fork-0.0.9.tar.gz", hash = "sha256:95b23cc5092af85080c716a6da68360f5ae4fcffa75f4a3aca5e539783cbcc3d"}, +] + [[package]] name = "docutils" version = "0.19" @@ -909,6 +920,25 @@ files = [ {file = "pycryptodome-3.20.0.tar.gz", hash = "sha256:09609209ed7de61c2b560cc5c8c4fbf892f8b15b1faf7e4cbffac97db1fffda7"}, ] +[[package]] +name = "pydoclint" +version = "0.5.7" +description = "A Python docstring linter that checks arguments, returns, yields, and raises sections" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pydoclint-0.5.7-py2.py3-none-any.whl", hash = "sha256:22561b8f876b7bd3d4966a3b7fe27bfdbfa41fa50d0719f13b08844a39e2717c"}, + {file = "pydoclint-0.5.7.tar.gz", hash = "sha256:d2938efc95233205822bebe5da5c8e1c4796da09988a2a73c2d6b63cef4577a6"}, +] + +[package.dependencies] +click = ">=8.1.0" +docstring-parser-fork = ">=0.0.9" +tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} + +[package.extras] +flake8 = ["flake8 (>=4)"] + [[package]] name = "pydocstyle" version = "6.3.0" @@ -1388,4 +1418,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "9d455f637b53b084cfaa245b00a4e9e25e1c161ddbf84803e85d1b090c47a3e3" +content-hash = "64ce220d4127b53420b0cc43c29783116a12a28a6d74260da61c71258f7ce514" diff --git a/pyproject.toml b/pyproject.toml index b37bb6c45..22f638b92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,8 @@ isort = "^5.11.5" flake8-isort = "^6.0.0" flake8-annotations = "3.1.1" flake8-absolute-import = "^1.0" -darglint = "^1.5.8" +pydoclint = "^0.5.7" +darglint = "^1.8.1" sphinx-rtd-theme = "^2.0.0" aiounittest = "^1.4.0" coverage = "^7.2.7" From 7b71b80e3a06cb755e027bbb4c7c05b48805b308 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 17 Sep 2024 18:56:27 -0400 Subject: [PATCH 05/11] remove darglint --- .darglint | 4 ---- .flake8 | 6 ++---- .pre-commit-config.yaml | 2 +- poetry.lock | 13 +------------ pyproject.toml | 3 +-- 5 files changed, 5 insertions(+), 23 deletions(-) delete mode 100644 .darglint diff --git a/.darglint b/.darglint deleted file mode 100644 index cdc16584b..000000000 --- a/.darglint +++ /dev/null @@ -1,4 +0,0 @@ -[darglint] -# Disable darglint checks for private functions. -ignore_regex=^_(.*) -ignore=DAR402 diff --git a/.flake8 b/.flake8 index c06aaa4ac..1ed094315 100644 --- a/.flake8 +++ b/.flake8 @@ -18,7 +18,7 @@ allow-init-docstring=True per-file-ignores = # For tests, disable type annotation and docstring linting. - tests/*: ANN D DAR + tests/*: ANN D # Select other tools to enable. @@ -30,8 +30,6 @@ per-file-ignores = # D enables docstrings warnings from pydocstyle. -# DAR enables docstring style linting via darglint. - # DIC enables docstring style linting via pydoclint. # F are errors reported by pyflakes, a tool which parses source files @@ -42,4 +40,4 @@ per-file-ignores = # W and E are warnings and errors reported by pycodestyle, which checks # your Python code against some of the style conventions in PEP 8. -select = ABS,ANN,DAR,DOC,BLK,D,E,F,I,W +select = ABS,ANN,DOC,BLK,D,E,F,I,W diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7ca00e5c8..b47381159 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: types: [python] - id: flake8 name: flake8 - entry: poetry run flake8 --darglint-ignore-regex="^_(.*)" + entry: poetry run flake8 language: system types: [python] - id: mypy diff --git a/poetry.lock b/poetry.lock index c53131061..99eccea58 100644 --- a/poetry.lock +++ b/poetry.lock @@ -365,17 +365,6 @@ files = [ [package.extras] toml = ["tomli"] -[[package]] -name = "darglint" -version = "1.8.1" -description = "A utility for ensuring Google-style docstrings stay up to date with the source code." -optional = false -python-versions = ">=3.6,<4.0" -files = [ - {file = "darglint-1.8.1-py3-none-any.whl", hash = "sha256:5ae11c259c17b0701618a20c3da343a3eb98b3bc4b5a83d31cdd94f5ebdced8d"}, - {file = "darglint-1.8.1.tar.gz", hash = "sha256:080d5106df149b199822e7ee7deb9c012b49891538f14a11be681044f0bb20da"}, -] - [[package]] name = "deprecated" version = "1.2.14" @@ -1418,4 +1407,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "64ce220d4127b53420b0cc43c29783116a12a28a6d74260da61c71258f7ce514" +content-hash = "1d6570a50e53023f8b3df0f2efecf3f56d8e0c99d75df881e186c88e8184c4c7" diff --git a/pyproject.toml b/pyproject.toml index 22f638b92..5b3482907 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,7 +51,6 @@ flake8-isort = "^6.0.0" flake8-annotations = "3.1.1" flake8-absolute-import = "^1.0" pydoclint = "^0.5.7" -darglint = "^1.8.1" sphinx-rtd-theme = "^2.0.0" aiounittest = "^1.4.0" coverage = "^7.2.7" @@ -81,7 +80,7 @@ precision = 2 [tool.poe.tasks] test_unit = "coverage run -m unittest discover tests/unit" test_integration = "coverage run -m unittest discover tests/integration" -lint = "poetry run flake8 xrpl tests snippets --darglint-ignore-regex=\"^_(.*)\"" +lint = "poetry run flake8 xrpl tests snippets" [tool.poe.tasks.test] cmd = "python3 -m unittest ${FILE_PATHS}" From 5b33dec075aeba9b85302e624fb21a58a6cec699 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 17 Sep 2024 18:59:56 -0400 Subject: [PATCH 06/11] fix typo --- xrpl/utils/xrp_conversions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xrpl/utils/xrp_conversions.py b/xrpl/utils/xrp_conversions.py index 884ca1a13..5eaaa4829 100644 --- a/xrpl/utils/xrp_conversions.py +++ b/xrpl/utils/xrp_conversions.py @@ -84,7 +84,7 @@ def drops_to_xrp(drops: str) -> Decimal: TypeError: if ``drops`` not given as a string XRPRangeException: if the given number of drops is invalid """ - if isinstance(drops, str): + if not isinstance(drops, str): raise TypeError(f"Drops must be provided as string (got {type(drops)})") drops = drops.strip() with localcontext(DROPS_DECIMAL_CONTEXT): From 674161bca96ae10e2400ef09183f1150376bfec4 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 17 Sep 2024 19:01:37 -0400 Subject: [PATCH 07/11] update poethepoet to latest --- poetry.lock | 8 ++++---- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/poetry.lock b/poetry.lock index 99eccea58..301670588 100644 --- a/poetry.lock +++ b/poetry.lock @@ -841,13 +841,13 @@ type = ["mypy (>=1.8)"] [[package]] name = "poethepoet" -version = "0.24.4" +version = "0.28.0" description = "A task runner that works well with poetry." optional = false python-versions = ">=3.8" files = [ - {file = "poethepoet-0.24.4-py3-none-any.whl", hash = "sha256:fb4ea35d7f40fe2081ea917d2e4102e2310fda2cde78974050ca83896e229075"}, - {file = "poethepoet-0.24.4.tar.gz", hash = "sha256:ff4220843a87c888cbcb5312c8905214701d0af60ac7271795baa8369b428fef"}, + {file = "poethepoet-0.28.0-py3-none-any.whl", hash = "sha256:db6946ff39a1244235950cd720ee7182107f64126d3dcc64c9a996cc4d755404"}, + {file = "poethepoet-0.28.0.tar.gz", hash = "sha256:5dc3ee036ab0c93e918b5caed628274618b07d788e5cff6c4ae480913cbe009c"}, ] [package.dependencies] @@ -1407,4 +1407,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "1d6570a50e53023f8b3df0f2efecf3f56d8e0c99d75df881e186c88e8184c4c7" +content-hash = "fc38d01f23b76685c52375c00911fcab5a3d92bcff242aba2f2e6fb884ce9b27" diff --git a/pyproject.toml b/pyproject.toml index 5b3482907..cdbe6c361 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,7 @@ coverage = "^7.2.7" Jinja2 = "^3.1.4" MarkupSafe = "2.1.5" Sphinx = "^5.3.0" -poethepoet = "^0.24.0" +poethepoet = "^0.28.0" [tool.isort] # Make sure that isort's settings line up with black From de8546440903c27a613db127db0bba595656f286 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Wed, 18 Sep 2024 19:02:37 -0400 Subject: [PATCH 08/11] fix typos --- .flake8 | 4 ++-- xrpl/transaction/main.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.flake8 b/.flake8 index 1ed094315..b173e07f0 100644 --- a/.flake8 +++ b/.flake8 @@ -18,7 +18,7 @@ allow-init-docstring=True per-file-ignores = # For tests, disable type annotation and docstring linting. - tests/*: ANN D + tests/*: ANN D DOC # Select other tools to enable. @@ -30,7 +30,7 @@ per-file-ignores = # D enables docstrings warnings from pydocstyle. -# DIC enables docstring style linting via pydoclint. +# DOC enables docstring style linting via pydoclint. # F are errors reported by pyflakes, a tool which parses source files # and finds invalid Python code. diff --git a/xrpl/transaction/main.py b/xrpl/transaction/main.py index 99f1ff43e..964edfd04 100644 --- a/xrpl/transaction/main.py +++ b/xrpl/transaction/main.py @@ -1,4 +1,5 @@ """High-level transaction methods with XRPL transactions.""" + import asyncio from typing import Optional From 687fba8c93e51246a28f1752b1b117ebfd27f08a Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Tue, 1 Oct 2024 17:20:10 -0400 Subject: [PATCH 09/11] fix merge --- poetry.lock | 2 +- pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/poetry.lock b/poetry.lock index 9d9f0ace4..d83d2cf03 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1409,4 +1409,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "fc38d01f23b76685c52375c00911fcab5a3d92bcff242aba2f2e6fb884ce9b27" +content-hash = "8fcc64d6fab31a48915cf94ee6864d478286ee220c70bed56391985ce8126fc8" diff --git a/pyproject.toml b/pyproject.toml index be050d59c..1a69b3db5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,8 +56,8 @@ aiounittest = "^1.4.0" coverage = "^7.2.7" Jinja2 = "^3.1.4" MarkupSafe = "2.1.5" -Sphinx = "^5.3.0" -poethepoet = "^0.19.0" +Sphinx = "^7.1.2" +poethepoet = "^0.28.0" [tool.isort] # Make sure that isort's settings line up with black From 16f4dc332c5f3a3dc1cdce46fcb04b670738c19d Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Fri, 25 Oct 2024 16:13:05 -0400 Subject: [PATCH 10/11] fix hash --- poetry.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 7e57da7bd..a3ef67a85 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1488,4 +1488,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.8.1" -content-hash = "8fcc64d6fab31a48915cf94ee6864d478286ee220c70bed56391985ce8126fc8" +content-hash = "00a5a440845df4788d6b6014ba4142a26b73d7f562dea9e1a7f127f5781f488f" From b30d6bf5e590d6d4d0503421a0a2c7f75a382297 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Fri, 20 Dec 2024 11:51:16 -0800 Subject: [PATCH 11/11] fix imports --- poetry.lock | 29 ++++++++++++++++++++++++----- pyproject.toml | 7 +++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/poetry.lock b/poetry.lock index a57163430..38ae220cd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -939,18 +939,37 @@ files = [ [[package]] name = "pydoclint" -version = "0.5.7" +version = "0.5.11" description = "A Python docstring linter that checks arguments, returns, yields, and raises sections" optional = false python-versions = ">=3.8" files = [ - {file = "pydoclint-0.5.7-py2.py3-none-any.whl", hash = "sha256:22561b8f876b7bd3d4966a3b7fe27bfdbfa41fa50d0719f13b08844a39e2717c"}, - {file = "pydoclint-0.5.7.tar.gz", hash = "sha256:d2938efc95233205822bebe5da5c8e1c4796da09988a2a73c2d6b63cef4577a6"}, + {file = "pydoclint-0.5.11-py2.py3-none-any.whl", hash = "sha256:7ea595c80a3f959defeed08752877b7b85bb4a8197df71dd79863258214b48b4"}, + {file = "pydoclint-0.5.11.tar.gz", hash = "sha256:abd3e428b1b8a318cafabcbe6355d4ccf27733267b9f2645e0fb967503f5ba8b"}, ] [package.dependencies] click = ">=8.1.0" -docstring-parser-fork = ">=0.0.9" +docstring_parser_fork = ">=0.0.9" +tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} + +[package.extras] +flake8 = ["flake8 (>=4)"] + +[[package]] +name = "pydoclint" +version = "0.5.13" +description = "A Python docstring linter that checks arguments, returns, yields, and raises sections" +optional = false +python-versions = ">=3.9" +files = [ + {file = "pydoclint-0.5.13-py2.py3-none-any.whl", hash = "sha256:ccdc587ee3de15adce1b962ff93bdf8740cfa9a2117607be28f24723e108956d"}, + {file = "pydoclint-0.5.13.tar.gz", hash = "sha256:5774acaeeb488ace1a9488bc10175025c2006379c237eb062e2ede9a206c121a"}, +] + +[package.dependencies] +click = ">=8.1.0" +docstring_parser_fork = ">=0.0.9" tomli = {version = ">=2.0.1", markers = "python_version < \"3.11\""} [package.extras] @@ -1542,4 +1561,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<4.0" -content-hash = "4e82534bd75fb2b7aa655f0d236a690f3b0bb1961a5b42c6366916f0ae28fdb2" +content-hash = "1f062dc4f6974d191c273d23dfbeab80b5b2fde0f04e7ab692fb7ae94e57d2ee" diff --git a/pyproject.toml b/pyproject.toml index 8c655bedf..a1ef55503 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ base58 = "^2.1.0" ECPy = "^1.2.5" typing-extensions = "^4.2.0" httpx = ">=0.18.1,<0.29.0" -websockets = ">=11,<14" +websockets = ">=11" Deprecated = "^1.2.13" types-Deprecated = "^1.2.9" pycryptodome = "^3.16.0" @@ -43,7 +43,10 @@ isort = "^5.11.5" flake8-isort = "^6.0.0" flake8-annotations = "^3.1.1" flake8-absolute-import = "^1.0" -pydoclint = "^0.5.7" +pydoclint = [ + { version = "<=0.5.12", python = "<3.9" }, + { version = "^0.5.13", python = ">=3.9" } +] sphinx-rtd-theme = "^3.0.2" aiounittest = "^1.4.0" coverage = "^7.2.7"