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 87bd1ef41..b173e07f0 100644 --- a/.flake8 +++ b/.flake8 @@ -11,9 +11,14 @@ 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 + tests/*: ANN D DOC # Select other tools to enable. @@ -25,7 +30,7 @@ per-file-ignores = # D enables docstrings warnings from pydocstyle. -# DAR enables docstring style linting via darglint. +# DOC 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 +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,BLK,D,E,F,I,W +select = ABS,ANN,DOC,BLK,D,E,F,I,W diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml index d97f3a586..c55db2ef7 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/.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/CONTRIBUTING.md b/CONTRIBUTING.md index 89bfea14b..262418473 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 19feffffe..96d989cc5 100644 --- a/poetry.lock +++ b/poetry.lock @@ -377,17 +377,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.15" @@ -405,6 +394,17 @@ wrapt = ">=1.10,<2" [package.extras] dev = ["PyTest", "PyTest-Cov", "bump2version (<1)", "jinja2 (>=3.0.3,<3.1.0)", "setuptools", "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.20.1" @@ -943,6 +943,44 @@ files = [ {file = "pycryptodome-3.21.0.tar.gz", hash = "sha256:f7787e0d469bdae763b876174cf2e6c0f7be79808af26b1da96f1a64bcf47297"}, ] +[[package]] +name = "pydoclint" +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.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" +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] +flake8 = ["flake8 (>=4)"] + [[package]] name = "pydocstyle" version = "6.3.0" @@ -1529,4 +1567,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<4.0" -content-hash = "6b2338dda53ffd9ba9c96e975584987377cca35a12d49e0fa61e0679396d800c" +content-hash = "1f062dc4f6974d191c273d23dfbeab80b5b2fde0f04e7ab692fb7ae94e57d2ee" diff --git a/pyproject.toml b/pyproject.toml index f57081b7b..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" -darglint = "^1.5.8" +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" @@ -74,6 +77,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" [tool.poe.tasks.test] cmd = "python3 -m unittest ${FILE_PATHS}" diff --git a/xrpl/core/binarycodec/types/serialized_type.py b/xrpl/core/binarycodec/types/serialized_type.py index cb78b778a..c6bdec6c0 100644 --- a/xrpl/core/binarycodec/types/serialized_type.py +++ b/xrpl/core/binarycodec/types/serialized_type.py @@ -16,7 +16,12 @@ class SerializedType(ABC): """The base class for all binary codec field types.""" def __init__(self: Self, buffer: bytes = bytes()) -> None: - """Construct a new SerializedType.""" + """ + Construct a new SerializedType. + + Args: + buffer: The buffer containing the data for the SerializedType. + """ self.buffer = buffer @classmethod @@ -86,5 +91,10 @@ def to_hex(self: Self) -> str: return self.buffer.hex().upper() def __len__(self: Self) -> int: - """Get the length of a SerializedType's bytes.""" + """ + Get the length of a SerializedType's bytes. + + Returns: + The number of bytes. + """ return len(self.buffer) diff --git a/xrpl/core/binarycodec/types/st_object.py b/xrpl/core/binarycodec/types/st_object.py index 9c43d92a2..e8c6dd12a 100644 --- a/xrpl/core/binarycodec/types/st_object.py +++ b/xrpl/core/binarycodec/types/st_object.py @@ -59,9 +59,9 @@ def _handle_xaddress(field: str, xaddress: str) -> Dict[str, Union[str, int]]: return {field: classic_address} +# 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: str) -> Union[str, int]: - # all of these fields have enum values that are used for serialization - # converts the string name to the corresponding enum code if field == "TransactionType": return get_transaction_type_code(value) if field == "TransactionResult": @@ -71,8 +71,8 @@ def _str_to_enum(field: str, value: str) -> Union[str, int]: return value +# reverse of the above function def _enum_to_str(field: str, value: int) -> Union[str, int]: - # reverse of the above function if field == "TransactionType": return get_transaction_type_name(value) if field == "TransactionResult":