-
Notifications
You must be signed in to change notification settings - Fork 795
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: Add ruff
rules, improve type annotations, improve ci performance
#3431
Conversation
[RUF002](https://docs.astral.sh/ruff/rules/ambiguous-unicode-character-docstring/) may be avoidable during schema generation, so I'm not doing any manual fixes right now.
Testing the effect this has with existing rules, prior to adding `pylint`, `refurb`
… violations with dummy variable
Almost all have autofixes, splitting out from [pylint](https://docs.astral.sh/ruff/rules/#pylint-pl) which is much larger in scope + fewer fixes
Across the 4 `PL.` categories, there are over 50 rules, with a mix of fixable, preview. Tried to be picky with what is added, because adding even 1 of the groups would generate a lot of manual fixes.
…_selection` `param_kwds` in `_selection` triggered `PLR6201`. Instead rewrote as a dictcomp.
`flake8-use-pathlib` rules all require manual fixes. > Found 70 errors. <details> <summary>Details</summary> ```md 20 PTH118 `os.path.join()` should be replaced by `Path` with `/` operator 12 PTH120 `os.path.dirname()` should be replaced by `Path.parent` 11 PTH100 `os.path.abspath()` should be replaced by `Path.resolve()` 11 PTH123 `open()` should be replaced by `Path.open()` 7 PTH110 `os.path.exists()` should be replaced by `Path.exists()` 6 PTH107 `os.remove()` should be replaced by `Path.unlink()` 3 PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` ```
Avoids [triggering](https://docs.python.org/3/library/inspect.html#inspect.getattr_static) on objects like `datum`, `expr`
```log Extension error (sphinxext.altairgallery): Handler <function main at 0x7f0873471ab0> for event 'builder-inited' threw an exception (exception: unsupported operand type(s) for +: 'PosixPath' and 'str') ```
@binste I can't seem to be able to reply to this comment
I do agree with this sentiment, and when I first added the alias in f1d9dc2 I used the name By the time I added it to this branch, I'd changed my mind and added the reasoning to the commit message:
I'm not sure about all IDEs, but for VSCode the "dangling" docstring will show on hover. Just spotted I need to update the example since https://github.com/microsoft/pylance-release/releases/tag/2024.6.100 added sphinx support.
That is fair. Although say for the example above, the arguments accepting I am open to an alternative, but the semantics of this alias and
Thank you. I was really suprised at how much more readable it made the signatures, especially those with multiple literals. |
Valid points. I can't come up with a better name either so let's give it a try like this. I'll merge this in to free up other PRs. Refinements such as updating examples can happen in a follow-up PR. |
Just seen this https://github.com/astral-sh/ruff/releases/tag/0.5.0 @binste thanks for reviewing & merging. I'll continue in another PR as suggested |
Fixes an issue identified in vega#3431 (comment) and addresses `typing.Optional`
Fixes https://github.com/vega/altair/actions/runs/9733301918/job/26860053484?pr=3452 This was due to `ruff` updating around the same time as vega#3431 (comment) The `SIM` rule that it is remapped to is already part of our config
Following vega#3431 a number of these are now importable. Additionally, I spotted the `encodings` parameter was annotated with `str`, but should be restricted to the constraints of `SingleDefUnitChannel_T`.
Following #3431 a number of these are now importable. Additionally, I spotted the `encodings` parameter was annotated with `str`, but should be restricted to the constraints of `SingleDefUnitChannel_T`.
https://docs.astral.sh/ruff/settings/#lint_mccabe_max-complexity Previously 18, the default is 10. As this rule was not in `[tool.ruff.lint.select]`, it was not used. Setting such a high limit hides opportunities to simplify large, complex functions. Many cases were resolved/improved in vega#3431. The remainder can use the *# noqa: C901* comment to serve as a TODO
Fixes: #3430
pyproject.toml
win32
andpyright
Stats from the first round of rules
ruff check . --statistics
Found 313 errors, 293 fixable
[*]
.Details
Tasks
RUF002
characterselif/else
, but is collapsed after lintingfrom __future__ import annotations
declaration at the top of each file.typing
constructs storing class objects - which would then be "stringified".python=3.14
suggesting requires further discussion
Future Rule Considerations