Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace darglint with pydoclint #749

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .darglint

This file was deleted.

11 changes: 8 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to remove this rule within the scope of this PR ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make the diff gigantic and much harder to review.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm


per-file-ignores =
# For tests, disable type annotation and docstring linting.
tests/*: ANN D DAR
tests/*: ANN D DOC

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider adding an ignore line here?

# Ignore the docstring linting errors
xrpl/*: DAR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can subdue these errors with this .flake8 configuration setting. See this suggestion: https://github.com/XRPLF/xrpl-py/pull/749/files#r1888218681

However, I don't know if it is wise to ignore the linter errors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to remove darglint manually as a dependency: poetry remove darglint

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that doesn't help:

xrpl-py-py3.11➜  xrpl-py git:(pydoclint) ✗ poetry remove darglint



The following packages were not found: darglint

What version of Python do you have? I am using Python 3.11, the CI/CD uses Python v3.8

Copy link
Collaborator Author

@mvadari mvadari Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using 3.11, so not sure what problem you're having. The DAR errors shouldn't be showing up at all, given that the flake8 config no longer includes them in the select list. My best suggestion is to nuke your .venv folder and reinstall.

mvadari@mvadari-H2R24-MBP xrpl-py % poetry run python --version
Python 3.11.4
mvadari@mvadari-H2R24-MBP xrpl-py % poetry run poe lint
Poe => poetry run flake8 xrpl tests snippets
mvadari@mvadari-H2R24-MBP xrpl-py % 

# Select other tools to enable.

Expand All @@ -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.
Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:

- name: Lint
run: |
poetry run flake8 xrpl tests snippets --darglint-ignore-regex="^_(.*)"
poetry run poe lint
mvadari marked this conversation as resolved.
Show resolved Hide resolved

- name: Type-check
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
115 changes: 77 additions & 38 deletions poetry.lock

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

9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include = ["LICENSE"]
packages = [{ include = "xrpl" }]

[tool.poetry.dependencies]
python = "^3.8"
python = "^3.8.1"
base58 = "^2.1.0"
ECPy = "^1.2.5"
typing-extensions = "^4.2.0"
Expand All @@ -34,16 +34,16 @@ types-Deprecated = "^1.2.9"
pycryptodome = "^3.16.0"

[tool.poetry.dev-dependencies]
flake8 = "^4.0.1"
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"
pydoclint = "^0.5.7"
sphinx-rtd-theme = "^3.0.0"
aiounittest = "^1.4.0"
coverage = "^7.2.7"
Expand Down Expand Up @@ -73,6 +73,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"
mvadari marked this conversation as resolved.
Show resolved Hide resolved

[tool.poe.tasks.test]
cmd = "python3 -m unittest ${FILE_PATHS}"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/core/binarycodec/types/test_serialized_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions xrpl/core/addresscodec/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions xrpl/core/binarycodec/types/serialized_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.

Expand Down
10 changes: 5 additions & 5 deletions xrpl/core/binarycodec/types/st_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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":
Expand Down
Loading