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

Stricter code quality rules (via ruff) #488

Merged
merged 13 commits into from Aug 20, 2023
Merged

Stricter code quality rules (via ruff) #488

merged 13 commits into from Aug 20, 2023

Conversation

tony
Copy link
Member

@tony tony commented Jul 8, 2023

Docs:

Adds:

  • "E", # pycodestyle
  • "F", # pyflakes
  • "I", # isort
  • "UP", # pyupgrade
  • "B", # flake8-bugbear
  • "C4", # flake8-comprehensions
  • "Q", # flake8-quotes
  • "PTH", # flake8-use-pathlib
  • "ERA", # eradicate
  • "SIM", # flake8-simplify
  • "TRY", # Trycertatops
  • "PERF", # Perflint
  • "RUF" # Ruff-specific rules

See also: tmux-python/tmuxp#879

@tony tony force-pushed the ruff-rules branch 2 times, most recently from 5735ba6 to e5c2139 Compare August 4, 2023 12:08
@tony tony force-pushed the ruff-rules branch 2 times, most recently from cf31b78 to e4dc454 Compare August 11, 2023 23:19
@tony tony force-pushed the ruff-rules branch 6 times, most recently from d58892b to 631d489 Compare August 20, 2023 10:43
src/libtmux/_vendor/version.py:198:19: TRY003 Avoid specifying long messages outside the exception class"
@tony tony force-pushed the ruff-rules branch 2 times, most recently from 1f8ad0b to efcbb4a Compare August 20, 2023 10:55
@codecov
Copy link

codecov bot commented Aug 20, 2023

Codecov Report

Merging #488 (eb42b5b) into master (a0cf146) will decrease coverage by 0.04%.
The diff coverage is 68.51%.

@@            Coverage Diff             @@
##           master     #488      +/-   ##
==========================================
- Coverage   88.92%   88.88%   -0.04%     
==========================================
  Files          35       35              
  Lines        3484     3508      +24     
  Branches      484      484              
==========================================
+ Hits         3098     3118      +20     
- Misses        278      282       +4     
  Partials      108      108              
Files Changed Coverage Δ
conftest.py 92.00% <ø> (ø)
src/libtmux/formats.py 100.00% <ø> (ø)
src/libtmux/server.py 66.97% <45.00%> (+1.22%) ⬆️
src/libtmux/common.py 83.33% <50.00%> (ø)
src/libtmux/window.py 78.57% <52.17%> (-0.31%) ⬇️
src/libtmux/_internal/query_list.py 47.27% <63.63%> (+1.36%) ⬆️
src/libtmux/session.py 76.00% <68.00%> (-0.56%) ⬇️
src/libtmux/exc.py 77.27% <70.58%> (-22.73%) ⬇️
src/libtmux/pane.py 92.38% <75.00%> (ø)
src/libtmux/pytest_plugin.py 83.33% <80.00%> (+1.75%) ⬆️
... and 9 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tony tony force-pushed the ruff-rules branch 5 times, most recently from f677bb5 to ed399aa Compare August 20, 2023 11:05
Fixed 81 errors:
- conftest.py:
    1 × I001 (unsorted-imports)
- docs/conf.py:
    2 × RUF100 (unused-noqa)
    1 × SIM108 (if-else-block-instead-of-if-exp)
    1 × I001 (unsorted-imports)
- src/libtmux/_internal/query_list.py:
    6 × ERA001 (commented-out-code)
    1 × SIM118 (in-dict-keys)
- src/libtmux/common.py:
    1 × UP031 (printf-string-formatting)
    1 × C408 (unnecessary-collection-call)
- src/libtmux/formats.py:
    2 × ERA001 (commented-out-code)
- src/libtmux/neo.py:
    3 × ERA001 (commented-out-code)
    1 × C408 (unnecessary-collection-call)
- src/libtmux/pane.py:
    4 × ERA001 (commented-out-code)
    4 × RUF002 (ambiguous-unicode-character-docstring)
    1 × RUF005 (collection-literal-concatenation)
    1 × UP032 (f-string)
- src/libtmux/pytest_plugin.py:
    1 × F841 (unused-variable)
    1 × SIM300 (yoda-conditions)
    1 × TRY201 (verbose-raise)
    1 × ERA001 (commented-out-code)
    1 × SIM105 (suppressible-exception)
    1 × I001 (unsorted-imports)
    1 × SIM118 (in-dict-keys)
    1 × PERF102 (incorrect-dict-iterator)
- src/libtmux/server.py:
    2 × C408 (unnecessary-collection-call)
    1 × RUF005 (collection-literal-concatenation)
    1 × B009 (get-attr-with-constant)
    1 × ERA001 (commented-out-code)
- src/libtmux/session.py:
    5 × C408 (unnecessary-collection-call)
    2 × RUF015 (unnecessary-iterable-allocation-for-first-element)
    1 × UP031 (printf-string-formatting)
    1 × ERA001 (commented-out-code)
    1 × UP032 (f-string)
- src/libtmux/test.py:
    1 × C408 (unnecessary-collection-call)
- src/libtmux/window.py:
    6 × UP032 (f-string)
    4 × ERA001 (commented-out-code)
    3 × C408 (unnecessary-collection-call)
    2 × UP031 (printf-string-formatting)
    1 × RUF005 (collection-literal-concatenation)
    1 × RUF015 (unnecessary-iterable-allocation-for-first-element)
- tests/legacy_api/test_common.py:
    1 × SIM300 (yoda-conditions)
- tests/legacy_api/test_server.py:
    3 × SIM300 (yoda-conditions)
- tests/test_common.py:
    1 × SIM300 (yoda-conditions)
- tests/test_pytest_plugin.py:
    1 × ERA001 (commented-out-code)
    1 × RUF015 (unnecessary-iterable-allocation-for-first-element)
- tests/test_server.py:
    3 × SIM300 (yoda-conditions)
e.g. invalid Server(color=...) argument
@tony tony changed the title Ruff rules: Stricter code quality rules Stricter code quality rules (via ruff) Aug 20, 2023
docs/conf.py:191:9: PERF203 `try`-`except` within a loop incurs performance overhead
src/libtmux/_internal/query_list.py:62:9: TRY300 Consider moving this statement to an `else` block
src/libtmux/_internal/query_list.py:297:19: TRY002 Create your own exception
src/libtmux/_internal/query_list.py:297:19: TRY003 Avoid specifying long messages outside the exception class
src/libtmux/_internal/query_list.py:337:25: TRY301 Abstract `raise` to an inner function
src/libtmux/_internal/query_list.py:337:31: TRY003 Avoid specifying long messages outside the exception class
src/libtmux/common.py:154:23: TRY003 Avoid specifying long messages outside the exception class
src/libtmux/common.py:191:23: TRY003 Avoid specifying long messages outside the exception class
src/libtmux/common.py:246:13: TRY400 Use `logging.exception` instead of `logging.error`
src/libtmux/neo.py:243:15: TRY003 Avoid specifying long messages outside the exception class
src/libtmux/pane.py:293:19: TRY003 Avoid specifying long messages outside the exception class
src/libtmux/pane.py:439:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/pane.py:446:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/pytest_plugin.py:230:5: TRY302 Remove exception handler; error is immediately re-raised
src/libtmux/server.py:146:13: TRY300 Consider moving this statement to an `else` block
src/libtmux/server.py:210:23: TRY003 Avoid specifying long messages outside the exception class
src/libtmux/server.py:241:13: TRY300 Consider moving this statement to an `else` block
src/libtmux/server.py:515:17: PERF401 Use a list comprehension to create a transformed list
src/libtmux/server.py:535:13: PERF401 Use a list comprehension to create a transformed list
src/libtmux/server.py:553:13: PERF401 Use a list comprehension to create a transformed list
src/libtmux/server.py:591:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/server.py:604:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/server.py:612:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/server.py:619:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/server.py:629:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/server.py:642:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/server.py:650:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/server.py:660:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/server.py:667:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/server.py:679:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/server.py:688:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/session.py:111:17: PERF401 Use a list comprehension to create a transformed list
src/libtmux/session.py:130:17: PERF401 Use a list comprehension to create a transformed list
src/libtmux/session.py:361:17: PERF401 Use a list comprehension to create a transformed list
src/libtmux/session.py:366:19: TRY003 Avoid specifying long messages outside the exception class
src/libtmux/session.py:373:19: TRY003 Avoid specifying long messages outside the exception class
src/libtmux/session.py:487:31: PTH111 `os.path.expanduser()` should be replaced by `Path.expanduser()`
src/libtmux/session.py:602:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/session.py:609:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/session.py:616:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/session.py:623:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/session.py:633:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/session.py:640:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/session.py:649:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/session.py:657:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/session.py:666:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/test.py:50:15: PTH100 `os.path.abspath()` should be replaced by `Path.resolve()`
src/libtmux/test.py:50:31: PTH120 `os.path.dirname()` should be replaced by `Path.parent`
src/libtmux/test.py:51:15: PTH100 `os.path.abspath()` should be replaced by `Path.resolve()`
src/libtmux/test.py:51:31: PTH118 `os.path.join()` should be replaced by `Path` with `/` operator
src/libtmux/test.py:52:33: PTH118 `os.path.join()` should be replaced by `Path` with `/` operator
src/libtmux/window.py:123:17: PERF401 Use a list comprehension to create a transformed list
src/libtmux/window.py:245:31: PTH111 `os.path.expanduser()` should be replaced by `Path.expanduser()`
src/libtmux/window.py:473:13: TRY400 Use `logging.exception` instead of `logging.error`
src/libtmux/window.py:633:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/window.py:640:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/window.py:647:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/window.py:654:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/window.py:664:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/window.py:671:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/window.py:680:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/window.py:688:9: B028 No explicit `stacklevel` keyword argument found
src/libtmux/window.py:697:9: B028 No explicit `stacklevel` keyword argument found
tests/legacy_api/test_common.py:34:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
tests/legacy_api/test_common.py:54:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
tests/legacy_api/test_common.py:70:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
tests/legacy_api/test_common.py:87:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
tests/legacy_api/test_server.py:152:10: B017 `pytest.raises(Exception)` should be considered evil
tests/test_common.py:33:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
tests/test_common.py:53:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
tests/test_common.py:69:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
tests/test_common.py:86:18: RUF012 Mutable class attributes should be annotated with `typing.ClassVar`
tests/test_server.py:169:10: B017 `pytest.raises(Exception)` should be considered evil
tests/test_window.py:206:5: B018 Found useless expression. Either assign it to a variable or remove it.
@tony tony merged commit 4d86cbd into master Aug 20, 2023
23 checks passed
@tony tony deleted the ruff-rules branch August 20, 2023 11:31
tony added a commit that referenced this pull request Aug 20, 2023
tony added a commit that referenced this pull request Aug 20, 2023
tony added a commit to tmux-python/tmuxp that referenced this pull request Sep 4, 2023
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.

None yet

1 participant