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: Switch to Ruff #112

Merged
merged 12 commits into from
Apr 22, 2024
Merged

chore: Switch to Ruff #112

merged 12 commits into from
Apr 22, 2024

Conversation

jmgate
Copy link
Collaborator

@jmgate jmgate commented Apr 22, 2024

Type: Task

Description

Use Ruff to replace a variety of linters and formatters. Also turn on many of the linters Ruff adds over our prior configuration, and address any findings.

Related Issues/PRs

Closes #56.

Commits

  1. chore: Switch to Ruff (6112943)

    Use Ruff to replace a variety of linters/formatters.

  2. docs: Add docstrings to test/example files (f0b7eb9)

  3. chore: Ignore security findings in tests/examples (f18ece4)

  4. refactor: Don't override Python builtins (9006adb)

  5. test: Use UTC timezone with datetime (25ff30f)

    Running flake8-datetimez via Ruff yielded the following findings:

    example/test_examples.py:88:25: DTZ005 `datetime.datetime.now()` called without a `tz` argument
    example/test_examples.py:89:25: DTZ007 Naive datetime constructed using `datetime.datetime.strptime()` without %z
    example/test_examples.py:125:13: DTZ005 `datetime.datetime.now()` called without a `tz` argument
    example/test_examples.py:126:25: DTZ007 Naive datetime constructed using `datetime.datetime.strptime()` without %z
    Found 4 errors.
    

    Specifying timezone info resolves the issues.

  6. refactor: Assign exception messages to variables (844c71a)

    Running flake8-errmsg via Ruff yielded the following findings:

    reverse_argparse/reverse_argparse.py:143:17: EM102 Exception must not use an f-string literal, assign to variable first
    reverse_argparse/reverse_argparse.py:461:17: EM102 Exception must not use an f-string literal, assign to variable first
    Found 2 errors.
    

    This change resolves the issues.

  7. refactor: Remove unnecessary shebang lines (a7ae1f6)

  8. test: Use tuples for parametrize variables (25d9be8)

  9. refactor: Ignore particular type error (9d412dd)

  10. refactor: Address Pylint findings (862bc62)

  11. refactor: Address Ruff-specific lint findings (076e199)

  12. patch: Force prefer_short to be keyword-only (f02c7f2)

    Turning on flake8-boolean-trap linting via Ruff resulted in the following findings:

    reverse_argparse/reverse_argparse.py:242:31: FBT002 Boolean default positional argument in function definition
    reverse_argparse/reverse_argparse.py:242:31: FBT001 Boolean-typed positional argument in function definition
    Found 2 errors.
    

    Switching prefer_short from a positional to a keyword-only argument addresses the problem.

    Note that this is technically a breaking change, but only for a "private" method, not in the package's public API. Therefore the change is not registered as a breaking change via Conventional Commit syntax, and no major version update will be created. Instead, this commit will force the creation of a patch release. If users were relying on the prior behavior of this internal method, they can simply switch to the keyword syntax when calling it.

@jmgate jmgate self-assigned this Apr 22, 2024
Copy link

codecov bot commented Apr 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.04%. Comparing base (a8b9989) to head (f02c7f2).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #112      +/-   ##
==========================================
+ Coverage   94.01%   94.04%   +0.03%     
==========================================
  Files           2        2              
  Lines         167      168       +1     
  Branches       43       43              
==========================================
+ Hits          157      158       +1     
  Misses          4        4              
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jmgate jmgate force-pushed the switch-to-ruff branch 14 times, most recently from e7b5af8 to eed88f8 Compare April 22, 2024 21:46
jmgate added 9 commits April 22, 2024 15:55
Running `flake8-datetimez` via Ruff yielded the following findings:

    example/test_examples.py:88:25:
    DTZ005 `datetime.datetime.now()` called without a `tz` argument
    example/test_examples.py:89:25:
    DTZ007 Naive datetime constructed using
    `datetime.datetime.strptime()` without %z
    example/test_examples.py:125:13:
    DTZ005 `datetime.datetime.now()` called without a `tz` argument
    example/test_examples.py:126:25:
    DTZ007 Naive datetime constructed using
    `datetime.datetime.strptime()` without %z
    Found 4 errors.

Specifying timezone info resolves the issues.
Running `flake8-errmsg` via Ruff yielded the following findings:

    reverse_argparse/reverse_argparse.py:143:17:
    EM102 Exception must not use an f-string literal, assign to variable
    first
    reverse_argparse/reverse_argparse.py:461:17:
    EM102 Exception must not use an f-string literal, assign to variable
    first
    Found 2 errors.

This changes resolves the issues.
Turning on `flake8-boolean-trap` linting via Ruff resulted in the
following findings:

    reverse_argparse/reverse_argparse.py:242:31:
    FBT002 Boolean default positional argument in function definition
    reverse_argparse/reverse_argparse.py:242:31:
    FBT001 Boolean-typed positional argument in function definition
    Found 2 errors.

Switching `prefer_short` from a positional to a keyword-only argument
addresses the problem.

Note that this is technically a breaking change, but only for a
"private" method, not in the package's public API.  Therefore the change
is not registered as a breaking change via Conventional Commit syntax,
and no major version update will be created.  Instead, this commit will
force the creation of a patch release.  If users were relying on the
prior behavior of this internal method, they can simply switch to the
keyword syntax when calling it.
@jmgate jmgate merged commit 21a02d3 into master Apr 22, 2024
13 checks passed
@jmgate jmgate deleted the switch-to-ruff branch April 22, 2024 22:02
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.

Explore ruff for linting
1 participant