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

chore: replace darglint with pydoclint #749

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

chore: replace darglint with pydoclint #749

wants to merge 8 commits into from

Conversation

mvadari
Copy link
Collaborator

@mvadari mvadari commented Sep 17, 2024

High Level Overview of Change

darglint, the docstring linter we use, hasn't been updated in 3 years. pydoclint is kept up to date and is also much faster (linting took 23 seconds previously and now only takes 9).

This PR also creates a lint command in poe, upgrades flake8 and poethepoet to the latest versions, and fixes all linter issues that arose from the upgrade.

Context of Change

Fixes #730

Type of Change

  • Refactor (non-breaking change that only restructures code)
  • Documentation Updates

Did you update CHANGELOG.md?

  • Yes
  • No, this change does not impact library users

Test Plan

The linter still passes.

Summary by CodeRabbit

  • New Features

    • Updated linting configuration to enforce stricter documentation standards across all functions.
    • Introduced a new linting task to streamline the linting process.
  • Bug Fixes

    • Improved type checking in functions for better robustness and flexibility.
  • Documentation

    • Enhanced clarity of error messages and comments in the codebase.
  • Chores

    • Updated dependencies for improved functionality and compliance with linting standards.

@mvadari
Copy link
Collaborator Author

mvadari commented Sep 19, 2024

@coderabbitai full review

Copy link

coderabbitai bot commented Sep 19, 2024

Actions performed

Full review triggered.

Copy link

coderabbitai bot commented Sep 19, 2024

Walkthrough

The changes in this pull request involve the removal of the darglint configuration and its replacement with pydoclint for linting docstrings. The .flake8 configuration has been updated to accommodate this transition, including modifications to linting rules and the introduction of a new linting task in the pyproject.toml. Additionally, several code files have undergone minor adjustments, primarily focusing on enhancing type checking and suppressing linting warnings related to annotations.

Changes

Files Change Summary
.darglint, .flake8, .pre-commit-config.yaml, CONTRIBUTING.md, pyproject.toml Removed darglint configuration, updated .flake8 settings to transition to pydoclint, and streamlined linting commands in various configuration files.
tests/unit/core/binarycodec/types/test_serialized_type.py, xrpl/core/addresscodec/codec.py, xrpl/core/binarycodec/types/serialized_type.py, xrpl/core/binarycodec/types/st_object.py, xrpl/models/base_model.py, xrpl/models/nested_model.py, xrpl/models/requests/generic_request.py, xrpl/models/response.py, xrpl/transaction/main.py, xrpl/utils/xrp_conversions.py Minor modifications to type checking and annotation suppression comments across multiple files to improve linting compliance without changing core functionality.

Assessment against linked issues

Objective Addressed Explanation
Replace darglint docstring linter (Issue #730)

🐰 In the meadow where bunnies play,
We’ve tidied up our code today!
With pydoclint now in sight,
Our docstrings shine so bright!
Hopping through the lines so neat,
A clearer path, oh what a treat!
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (3)
.flake8 (1)

14-17: Temporary workaround looks good, but track the TODO.

Allowing docstrings in __init__ functions as a temporary measure for easier migration from darglint is a pragmatic approach. However, please ensure that the TODO comment is tracked and addressed in the future to maintain consistency with standard docstring conventions.

xrpl/core/binarycodec/types/st_object.py (2)

61-63: Linting warning suppressed, but consider addressing the underlying issue.

The addition of the # noqa: ANN401 comment suppresses the linting warning related to the return type annotation of the _str_to_enum function. While this allows the code to pass the linting checks, it's important to consider addressing the underlying issue to improve code quality and maintainability.

Consider updating the return type annotation to accurately reflect the possible return values of the function. This will not only resolve the linting warning but also provide better type information for users of the function.


73-74: Linting warning suppressed, but consider addressing the underlying issue.

The addition of the # noqa: ANN401 comment suppresses the linting warning related to the return type annotation of the _enum_to_str function. While this allows the code to pass the linting checks, it's important to consider addressing the underlying issue to improve code quality and maintainability.

Consider updating the return type annotation to accurately reflect the possible return values of the function. This will not only resolve the linting warning but also provide better type information for users of the function.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 17aad31 and de85464.

Files ignored due to path filters (1)
  • poetry.lock is excluded by !**/*.lock
Files selected for processing (16)
  • .darglint (0 hunks)
  • .flake8 (3 hunks)
  • .github/workflows/unit_test.yml (1 hunks)
  • .pre-commit-config.yaml (1 hunks)
  • CONTRIBUTING.md (1 hunks)
  • pyproject.toml (3 hunks)
  • tests/unit/core/binarycodec/types/test_serialized_type.py (1 hunks)
  • xrpl/core/addresscodec/codec.py (1 hunks)
  • xrpl/core/binarycodec/types/serialized_type.py (2 hunks)
  • xrpl/core/binarycodec/types/st_object.py (2 hunks)
  • xrpl/models/base_model.py (3 hunks)
  • xrpl/models/nested_model.py (1 hunks)
  • xrpl/models/requests/generic_request.py (1 hunks)
  • xrpl/models/response.py (2 hunks)
  • xrpl/transaction/main.py (1 hunks)
  • xrpl/utils/xrp_conversions.py (3 hunks)
Files not reviewed due to no reviewable changes (1)
  • .darglint
Additional comments not posted (26)
.pre-commit-config.yaml (1)

24-24: LGTM! The change aligns with the PR objective of replacing darglint with pydoclint.

The removal of the --darglint-ignore-regex argument from the flake8 command is consistent with the goal of replacing darglint with pydoclint for docstring linting. This change may result in additional warnings being reported during the pre-commit checks, as the specified darglint warnings will no longer be ignored.

Ensure that all relevant docstrings have been updated to comply with the new linting rules enforced by pydoclint. The PR objectives indicate that all linter issues arising from the upgrades have been addressed, which suggests that the necessary updates have been made.

.flake8 (3)

21-21: LGTM!

Updating the per-file-ignores setting for test files to use DOC instead of DAR aligns with the PR objective of replacing darglint with pydoclint. This ensures that test files are linted using the new docstring style rules.


33-33: Comment adds clarity.

Adding a comment to clarify that DOC enables docstring style linting via pydoclint is helpful for developers. It provides a clear indication of the tool being used for this purpose.


43-43: LGTM!

Updating the select option to include DOC and remove DAR aligns with the PR objective of replacing darglint with pydoclint. This change ensures that the linter applies the new docstring style rules consistently across the codebase.

pyproject.toml (6)

33-33: Clarify the reasoning behind the Python version bump.

The Python version requirement change from ^3.8 to ^3.8.1 looks good and is unlikely to cause any compatibility issues. However, could you please provide some context on why the minimum version was bumped specifically to 3.8.1? This will help maintain a clear record of the rationale behind the change.


44-44: Verify the impact of the flake8 and flake8-annotations upgrades.

The upgrades to flake8 (to ^7.0.0) and flake8-annotations (to 3.1.1) look good, considering that the PR objectives state all linter issues arising from these upgrades have been addressed.

However, given that the flake8 upgrade is a major version bump, it would be prudent to double-check that the new linting rules do not flag any unintended issues in the codebase. Please verify that the linter passes cleanly after these upgrades.

Also applies to: 51-51


53-53: Monitor pydoclint's stability and verify its impact on the codebase.

The migration from darglint to pydoclint looks good as it aligns with the PR objective of replacing the outdated darglint with a more actively maintained and faster alternative. The reduction in linting time from 23 seconds to 9 seconds is a significant improvement.

However, please note that pydoclint is still in an early version (^0.5.7), which may indicate potential instability or future breaking changes. It would be wise to monitor pydoclint's releases and stability going forward.

Additionally, please verify that the new pydoclint rules do not flag any unintended documentation issues in the codebase.


60-60: Provide more context on the poethepoet upgrade.

The upgrade of poethepoet from ^0.19.0 to ^0.28.0 looks good as it is a minor version bump, which generally indicates the addition of new features and bug fixes without introducing breaking changes.

However, could you please provide more context on the motivation behind this upgrade? Are there any specific features or fixes from the newer poethepoet versions that are being leveraged in this project? This information will help maintain a clear record of the reasoning behind the upgrade.


83-83: LGTM!

The addition of the lint task under [tool.poe.tasks] is a great improvement to the project's linting capabilities. Running flake8 on the xrpl, tests, and snippets directories will help maintain code quality and consistency by enforcing coding standards and identifying potential issues early in the development process. This task will be a valuable addition to the development workflow and CI/CD pipeline.


Line range hint 1-90: Great work on improving the project's dependencies and linting capabilities!

The changes made in this PR, including the dependency upgrades, migration to pydoclint, and addition of the lint task, align well with the stated objectives of keeping the project up-to-date, improving performance, and enhancing code quality. These changes collectively contribute to a better development workflow, increased maintainability, and more consistent code.

The migration to pydoclint and the addition of the lint task are particularly noteworthy, as they can significantly reduce linting time and catch potential issues early in the development process.

Overall, the changes look good, subject to addressing any outstanding questions or concerns raised in the previous review comments. Keep up the great work!

tests/unit/core/binarycodec/types/test_serialized_type.py (1)

51-51: LGTM!

The change from type(fixture.test_json) == dict to isinstance(fixture.test_json, dict) is a good improvement. It enhances the robustness of the type checking by allowing for subclassing, which is more Pythonic and flexible.

xrpl/models/nested_model.py (1)

24-24: Verify if suppressing the linting warning is justified.

The change of adding the # noqa: ANN401 comment directive to suppress the specific linting warning related to type annotations does not impact the functionality or correctness of the is_dict_of_model method.

However, please ensure that suppressing the ANN401 warning is justified and aligns with the project's linting guidelines. If the suppression is deemed necessary, consider adding a comment explaining the reason for suppressing the warning to maintain code clarity.

To verify the suppression, run the following script:

Verification successful

ANN401 suppression is justified and consistent with project practices.

The addition of # noqa: ANN401 to suppress the linting warning for the Any type annotation in the is_dict_of_model method is justified and aligns with the project's coding practices. Here's why:

  1. The suppression is used consistently throughout the codebase for functions with Any type annotations, indicating a deliberate coding style choice.
  2. The use of Any type and its suppression appears necessary due to the nature of the XRPL library, which likely needs to handle various data types flexibly.
  3. The suppression is not overused, appearing only in specific scenarios where the Any type is required.
  4. The project demonstrates a judicious use of linting suppressions overall, suggesting that this particular suppression is part of a well-considered approach to code quality.

The change is approved, as it maintains consistency with the existing codebase practices and does not impact the functionality of the method.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if suppressing the ANN401 linting warning is justified.

# Test: Search for the suppression comment in the codebase. Expect: Only occurrences in justified cases.
rg --type python $'# noqa: ANN401'

Length of output: 66


Script:

#!/bin/bash
# Description: Verify the usage of linting suppressions in Python files

# Search for "# noqa: ANN401" in Python files
echo "Occurrences of '# noqa: ANN401':"
fd -e py -x rg -n "# noqa: ANN401" {}

echo -e "\nAll occurrences of 'noqa' in Python files:"
fd -e py -x rg -n "# noqa:" {}

echo -e "\nPython files containing 'noqa':"
fd -e py -x rg -l "# noqa:" {} | sort | uniq

Length of output: 5183

xrpl/core/binarycodec/types/serialized_type.py (3)

28-28: Suppressing ANN401 linting error for flexibility.

The addition of the # noqa: ANN401 comment directive to suppress the linting error for the Any type annotation on the length_hint parameter is a reasonable decision. It allows subclasses to define their own type requirements for length_hint, providing flexibility in the implementation.

While using Any is generally discouraged, in this case, it serves a purpose to accommodate different use cases in subclasses. The suppression of the linting error is justified given the context and the need for adaptability.


34-34: Suppressing D102 and ANN401 linting errors for flexibility and brevity.

The addition of the # noqa: D102 ANN401 comment directive to suppress the linting errors for the missing docstring and the Any type annotation on the value parameter is a reasonable decision in this context. It allows the from_value method to accept different types of values, providing flexibility in the implementation.

While missing docstrings and using Any are generally discouraged, in this case, the developer has made a conscious choice to prioritize flexibility and brevity. The suppression of the linting errors is justified given the specific requirements and design decisions of the codebase.


57-57: Suppressing ANN401 linting error for flexibility in JSON representation.

The addition of the # noqa: ANN401 comment directive to suppress the linting error for the Any type annotation on the return value of the to_json method is a reasonable decision. It allows the method to return different types of JSON representations, providing flexibility in the implementation.

While using Any is generally discouraged, in this case, it serves a purpose to accommodate different JSON structures that may be returned by subclasses or overridden implementations. The suppression of the linting error is justified given the context and the need for adaptability in the JSON representation.

xrpl/models/requests/generic_request.py (1)

31-31: LGTM!

The addition of the # noqa: ANN401 directive to suppress the linting warning related to the lack of type annotation for the kwargs parameter is appropriate in this case. The directive indicates that the developer has intentionally chosen not to annotate kwargs with a specific type, as it is meant to accept any keyword arguments.

The change addresses the linting feedback without altering the functionality of the __init__ method, which remains unchanged. This stylistic adjustment improves code quality while maintaining the intended behavior of the method.

xrpl/utils/xrp_conversions.py (2)

39-39: LGTM!

The change from type(xrp) == str to isinstance(xrp, str) is an improvement as it allows for subclassing and is considered a best practice for type checking in Python. The rest of the function logic remains unchanged, and the overall functionality is not affected.


87-87: LGTM!

The change from type(drops) != str to not isinstance(drops, str) is an improvement as it allows for subclassing and is considered a best practice for type checking in Python. The rest of the function logic remains unchanged, and the overall functionality is not affected.

xrpl/transaction/main.py (1)

2-2: LGTM!

Adding a blank line after the module docstring is consistent with the PEP 8 style guide and enhances code readability. Good catch!

xrpl/models/response.py (2)

95-95: LGTM!

The addition of the # noqa: ANN401 comment suppresses the linting rule ANN401 for this function. This rule is likely related to missing type annotations. Since this is an internal function and the types can be inferred from the context, suppressing this specific rule is acceptable.


114-114: LGTM!

Similar to the _do_contains_partial_payment function, the addition of the # noqa: ANN401 comment suppresses the linting rule ANN401 for this function. This rule is likely related to missing type annotations. Since this is an internal function and the types can be inferred from the context, suppressing this specific rule is acceptable.

xrpl/core/addresscodec/codec.py (1)

43-44: LGTM!

Splitting the long error message into two lines improves readability without altering the semantic content. The error message still conveys the same information about the mismatch between the length of the provided bytestring and the expected length.

CONTRIBUTING.md (1)

69-69: LGTM!

The change from directly running flake8 to using poetry run poe lint is a good improvement. It abstracts the linting process and makes it easier for contributors to run the linter with the correct arguments and configurations. This reduces the chances of contributors running the linter with incorrect settings and ensures consistency across all contributions.

xrpl/models/base_model.py (3)

88-88: LGTM!

The addition of the # noqa: ANN401 comment is used to suppress a specific type annotation related linting warning (likely from the flake8-annotations plugin). This is an acceptable way to silence the linter when the type hint is complex or the linter is raising a false positive. The method functionality remains unaffected.


153-153: LGTM!

As explained in the previous comment, the # noqa: ANN401 comment is an acceptable way to suppress a specific type annotation related linting warning when the type hint is complex or the linter is raising a false positive. The method functionality remains unaffected.


324-324: LGTM!

As explained in the previous comments, the # noqa: ANN401 comment is an acceptable way to suppress a specific type annotation related linting warning when the type hint is complex or the linter is raising a false positive. The method functionality remains unaffected.

@@ -49,7 +49,7 @@ jobs:

- name: Lint
run: |
poetry run flake8 xrpl tests snippets --darglint-ignore-regex="^_(.*)"
poetry run poe lint
Copy link

@coderabbitai coderabbitai bot Sep 19, 2024

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Review and adjust the new linting configuration

The change to poetry run poe lint does include linting checks, but the configuration has changed:

  • The linting now uses the Google docstring convention instead of NumPy.
  • Some docstring-related rules (D205, D212, D415) are now ignored.
  • Docstring linting is disabled for test files.

Please review the new configuration in the .flake8 file to ensure it meets the project's needs, especially regarding docstring conventions and ignored rules. You may need to update the codebase to comply with the Google docstring convention if it was previously using NumPy.

Analysis chain

Verify if the specific regex option for ignoring certain docstring checks is still required.

The change to use poetry run poe lint improves the organization of the linting process by encapsulating multiple linting tools or configurations under the poe command.

However, please verify if the specific regex option --docstring-convention=numpy --ignore=D100,D101,D102,D103,D104,D105,D106,D107 for ignoring certain docstring checks is still required and included in the new poe lint command. If not, it might lead to new linting errors related to docstrings.

To verify if the specific regex option is still required, run the following script:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if the specific regex option for ignoring certain docstring checks is still required.

# Test 1: Search for the specific regex option in the `poe` configuration file. 
# Expect: The specific regex option is present in the `poe` configuration file.
rg --type toml $'--docstring-convention=numpy --ignore=D100,D101,D102,D103,D104,D105,D106,D107' pyproject.toml

# Test 2: Run the `poe lint` command and check for docstring-related linting errors. 
# Expect: No docstring-related linting errors are reported.
poetry run poe lint

Length of output: 633


Script:

#!/bin/bash
# Description: Verify if the specific regex option for ignoring certain docstring checks is still required.

# Test 1: Search for flake8 configuration in pyproject.toml
echo "Searching for flake8 configuration in pyproject.toml:"
cat pyproject.toml | sed -n '/\[tool\.flake8\]/,/^\[/p'

# Test 2: Search for poe tasks related to linting in pyproject.toml
echo "Searching for poe tasks related to linting in pyproject.toml:"
cat pyproject.toml | sed -n '/\[tool\.poe\.tasks\]/,/^\[/p' | grep -i 'lint'

# Test 3: Check if there's a separate .flake8 configuration file
echo "Checking for .flake8 configuration file:"
if [ -f ".flake8" ]; then
    cat .flake8
else
    echo ".flake8 file not found"
fi

# Test 4: List all Python files in the project
echo "Listing Python files in the project:"
find . -name "*.py" | head -n 5

Length of output: 2245

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The linting always used the Google docstring convention. The settings used are still in the .flake8 file, the only one not included is the darglint-specific error (which wasn't supported by the .flake8 file).

Copy link

Choose a reason for hiding this comment

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

@mvadari, thank you for the clarification! It's helpful to know that the linting has always used the Google docstring convention and that the settings are still in the .flake8 file, except for the darglint-specific error which wasn't supported there. I appreciate your explanation.

(^.^)?


Learnings added
Learnt from: mvadari
PR: XRPLF/xrpl-py#749
File: .github/workflows/unit_test.yml:52-52
Timestamp: 2024-09-19T19:59:13.121Z
Learning: - The project has always used the Google docstring convention for linting.
- The linting settings are in the `.flake8` file.
- The darglint-specific error wasn't supported in `.flake8`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace darglint docstring linter
1 participant