-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Ruff 0.10 #16600
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
Ruff 0.10 #16600
Conversation
44eec2b
to
e4e1c58
Compare
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
TC006 | 839 | 839 | 0 | 0 | 0 |
LOG015 | 287 | 287 | 0 | 0 | 0 |
UP015 | 110 | 55 | 55 | 0 | 0 |
A005 | 103 | 0 | 103 | 0 | 0 |
PLR1714 | 62 | 31 | 31 | 0 | 0 |
PTH208 | 59 | 59 | 0 | 0 | 0 |
C420 | 57 | 57 | 0 | 0 | 0 |
F405 | 48 | 0 | 48 | 0 | 0 |
PLW1508 | 46 | 46 | 0 | 0 | 0 |
UP038 | 39 | 0 | 39 | 0 | 0 |
SIM905 | 36 | 36 | 0 | 0 | 0 |
S704 | 30 | 30 | 0 | 0 | 0 |
PLC1802 | 29 | 29 | 0 | 0 | 0 |
SIM103 | 26 | 13 | 13 | 0 | 0 |
PYI019 | 19 | 19 | 0 | 0 | 0 |
RUF051 | 18 | 18 | 0 | 0 | 0 |
RUF046 | 16 | 16 | 0 | 0 | 0 |
DTZ901 | 11 | 11 | 0 | 0 | 0 |
F811 | 9 | 0 | 9 | 0 | 0 |
F403 | 9 | 0 | 9 | 0 | 0 |
RUF040 | 3 | 3 | 0 | 0 | 0 |
RUF041 | 2 | 2 | 0 | 0 | 0 |
TC004 | 1 | 1 | 0 | 0 | 0 |
S320 | 1 | 0 | 1 | 0 | 0 |
RUF100 | 1 | 0 | 1 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+30 -115 violations, +0 -0 fixes in 5 projects; 50 projects unchanged)
apache/airflow (+1 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL
- providers/amazon/src/airflow/providers/amazon/aws/hooks/base_aws.py:395:15: S320 Using `lxml` to parse untrusted data is known to be vulnerable to XML attacks - providers/fab/src/airflow/providers/fab/auth_manager/security_manager/override.py:2344:19: RUF035 Unsafe use of `markupsafe.Markup` detected + providers/fab/src/airflow/providers/fab/auth_manager/security_manager/override.py:2344:19: S704 Unsafe use of `markupsafe.Markup` detected
apache/superset (+7 -46 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL
- superset/async_events/async_query_manager.py:269:12: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)` - superset/cli/main.py:55:12: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)` - superset/commands/dataset/importers/v1/utils.py:212:12: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)` - superset/connectors/sqla/models.py:1308:16: RUF035 Unsafe use of `markupsafe.Markup` detected + superset/connectors/sqla/models.py:1308:16: S704 Unsafe use of `markupsafe.Markup` detected - superset/connectors/sqla/models.py:529:17: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)` - superset/connectors/sqla/models.py:562:12: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)` - superset/connectors/sqla/models.py:566:35: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)` - superset/connectors/sqla/models.py:568:37: UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)` ... 33 additional changes omitted for rule UP038 - superset/models/dashboard.py:225:16: RUF035 Unsafe use of `markupsafe.Markup` detected + superset/models/dashboard.py:225:16: S704 Unsafe use of `markupsafe.Markup` detected - superset/models/helpers.py:538:16: RUF035 Unsafe use of `markupsafe.Markup` detected + superset/models/helpers.py:538:16: S704 Unsafe use of `markupsafe.Markup` detected - superset/models/helpers.py:567:16: RUF035 Unsafe use of `markupsafe.Markup` detected + superset/models/helpers.py:567:16: S704 Unsafe use of `markupsafe.Markup` detected - superset/models/slice.py:338:16: RUF035 Unsafe use of `markupsafe.Markup` detected + superset/models/slice.py:338:16: S704 Unsafe use of `markupsafe.Markup` detected - superset/models/sql_lab.py:445:16: RUF035 Unsafe use of `markupsafe.Markup` detected ... 35 additional changes omitted for project
freedomofpress/securedrop (+21 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview
+ securedrop/journalist_app/account.py:100:20: S704 Unsafe use of `markupsafe.Markup` detected + securedrop/journalist_app/account.py:87:20: S704 Unsafe use of `markupsafe.Markup` detected + securedrop/journalist_app/admin.py:224:32: S704 Unsafe use of `markupsafe.Markup` detected + securedrop/journalist_app/admin.py:279:20: S704 Unsafe use of `markupsafe.Markup` detected + securedrop/journalist_app/admin.py:295:20: S704 Unsafe use of `markupsafe.Markup` detected + securedrop/journalist_app/col.py:103:17: S704 Unsafe use of `markupsafe.Markup` detected + securedrop/journalist_app/col.py:75:13: S704 Unsafe use of `markupsafe.Markup` detected + securedrop/journalist_app/main.py:169:17: S704 Unsafe use of `markupsafe.Markup` detected + securedrop/journalist_app/main.py:192:21: S704 Unsafe use of `markupsafe.Markup` detected + securedrop/journalist_app/main.py:203:21: S704 Unsafe use of `markupsafe.Markup` detected ... 11 additional changes omitted for project
qdrant/qdrant-client (+0 -66 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview
- qdrant_client/http/api/aliases_api.py:52:54: F405 `AsyncApiClient` may be undefined, or defined from star imports - qdrant_client/http/api/aliases_api.py:5:27: F811 Redefinition of unused `BaseModel` from line 4 - qdrant_client/http/api/aliases_api.py:7:1: F403 `from qdrant_client.http.models import *` used; unable to detect undefined names - qdrant_client/http/api/beta_api.py:51:54: F405 `AsyncApiClient` may be undefined, or defined from star imports - qdrant_client/http/api/beta_api.py:5:27: F811 Redefinition of unused `BaseModel` from line 4 - qdrant_client/http/api/beta_api.py:7:1: F403 `from qdrant_client.http.models import *` used; unable to detect undefined names - qdrant_client/http/api/collections_api.py:52:54: F405 `AsyncApiClient` may be undefined, or defined from star imports - qdrant_client/http/api/collections_api.py:5:27: F811 Redefinition of unused `BaseModel` from line 4 - qdrant_client/http/api/collections_api.py:7:1: F403 `from qdrant_client.http.models import *` used; unable to detect undefined names - qdrant_client/http/api/distributed_api.py:52:54: F405 `AsyncApiClient` may be undefined, or defined from star imports - qdrant_client/http/api/distributed_api.py:5:27: F811 Redefinition of unused `BaseModel` from line 4 - qdrant_client/http/api/distributed_api.py:7:1: F403 `from qdrant_client.http.models import *` used; unable to detect undefined names - qdrant_client/http/api/indexes_api.py:126:19: F405 `WriteOrdering` may be undefined, or defined from star imports - qdrant_client/http/api/indexes_api.py:144:19: F405 `WriteOrdering` may be undefined, or defined from star imports - qdrant_client/http/api/indexes_api.py:162:19: F405 `WriteOrdering` may be undefined, or defined from star imports - qdrant_client/http/api/indexes_api.py:180:19: F405 `WriteOrdering` may be undefined, or defined from star imports ... 41 additional changes omitted for rule F405 - qdrant_client/http/api/indexes_api.py:5:27: F811 Redefinition of unused `BaseModel` from line 4 - qdrant_client/http/api/indexes_api.py:7:1: F403 `from qdrant_client.http.models import *` used; unable to detect undefined names - qdrant_client/http/api/points_api.py:5:27: F811 Redefinition of unused `BaseModel` from line 4 - qdrant_client/http/api/points_api.py:7:1: F403 `from qdrant_client.http.models import *` used; unable to detect undefined names - qdrant_client/http/api/search_api.py:5:27: F811 Redefinition of unused `BaseModel` from line 4 - qdrant_client/http/api/search_api.py:7:1: F403 `from qdrant_client.http.models import *` used; unable to detect undefined names ... 44 additional changes omitted for project
zulip/zulip (+1 -1 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL
- zerver/views/documentation.py:292:35: RUF035 Unsafe use of `markupsafe.Markup` detected + zerver/views/documentation.py:292:35: S704 Unsafe use of `markupsafe.Markup` detected
Changes by rule (7 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
F405 | 48 | 0 | 48 | 0 | 0 |
UP038 | 39 | 0 | 39 | 0 | 0 |
S704 | 30 | 30 | 0 | 0 | 0 |
RUF035 | 9 | 0 | 9 | 0 | 0 |
F811 | 9 | 0 | 9 | 0 | 0 |
F403 | 9 | 0 | 9 | 0 | 0 |
S320 | 1 | 0 | 1 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
Summary -- Stabilizes LOG015. The tests and docs looked good. Test Plan -- 1 closed documentation issue from 4 days after the rule was added, but no other issues or PRs.
…`) (#16655) Summary -- Stabilizes B911. Tests and docs looked good. Test Plan -- 0 issues or PRs, open or closed
Summary -- Stabilizes RUF051. The tests and docs looked good. Test Plan -- 1 closed documentation issue from 4 days after the rule was added and 1 typo fix from the same day it was added, but no other issues or PRs.
## Summary Follow-up to #16659. This change adds tests for these three cases, which are (also) not covered by existing tests: * `# noqa: A` (lone incomplete code) * `# noqa: A123, B` (complete codes, last one incomplete) * `# noqa: A123B` (squashed codes, last one incomplete)
…10`) (#16656) Summary -- Stabilizes PTH210. Tests and docs looked good. Test Plan -- Mentioned in 1 open issue around Python 3.14 support (`"."` becomes a valid suffix in 3.14). Otherwise no issues or PRs since 2024-12-12, 6 days after the rule was added.
Summary -- Stabilizes RUF041. The tests are already in the right place, and the docs look good. Test Plan -- 0 issues, 1 [PR] fixing nested literals and unions the day after the rule was added. No changes since then I wonder if the fix in that PR could be relevant for #16639, where I noticed a potential issue with `Union`. It could be unrelated, though. [PR]: #14641
## Summary Follow-up to #16677. This change converts all unit tests (69 of them) in `noqa.rs` to use inline snapshots instead. It extends the file by more than 1000 lines, but the tests are now much easier to read and reason about. ## Test Plan `cargo insta test`.
Summary -- Stabilizes DTZ901, renames the rule function to match the rule name, removes the `preview_rules` test, and handles some nits in the docs (mention `min` first to match the rule name too). Test Plan -- 1 closed issue on 2024-11-12, 4 days after the rule was added. No issues since
Summary -- Stabilizes S704, which is also being recoded from RUF035 in 0.10. Test Plan -- Existing tests with `PreviewMode` removed from the settings. There was one issue closed on 2024-12-20 calling the rule noisy and asking for a config option, but the option was added and then there were no more issues or PRs.
## Summary This PR deprecates UP038. Using PEP 604 syntax in `isinstance` and `issubclass` calls isn't a recommended pattern (or community agreed best practice) and it negatively impacts performance. Resolves #7871 ## Test Plan I tested that selecting `UP038` results in a warning in no-preview mode and an error in preview mode
…PT031`) (#16678) ## Summary This PR stabilizes the behavior change introduced in #15542 to allow for statements with an empty body in `pytest.raises` and `pytest.warns` with statements. This raised an error before but is now allowed: ```py with pytest.raises(KeyError, match='unknown'): async for _ in gpt.generate(gpt_request): pass ``` The same applies to ```py with pytest.raises(KeyError, match='unknown'): async for _ in gpt.generate(gpt_request): ... ``` There have been now new issues or PRs related to PT012 or PT031 since this behavior change was introduced in ruff 0.9.3 (January 23rd).
…LW1508`) (#16674) ## Summary This PR stabilizes the new behavior introduced in #14512 to also detect defalut value arguemnts to `os.environ.get` that have an invalid type (not `str`). There's an upstream issue for this behavior change pylint-dev/pylint#10092 that was accepted and a PR, but it hasn't been merged yet. This behavior change was first shipped with Ruff 0.8.1 (Nov 22). There has only be one PR since the new behavior was introduced but it was unrelated to the scope increase (#14841).
## Summary This PR stabilizes the preview behavior introduced in #15905 The behavior change is that the rule now also recognizes `type(expr) is type(None)` comparisons where `expr` isn't a name expression. For example, the rule now detects `type(a.b) is type(None)` and suggests rewriting the comparison to `a.b is None`. The new behavior was introduced with Ruff 0.9.5 (6th of February), about a month ago. There are no open issues or PRs related to this rule (or behavior change).
…nvalid-argument-name`) (#16667) ## Summary This PR stabilizes the preview behavior for `invalid-argument-name` (`N803`) to ignore argument names of functions decorated with `typing.override` because these methods are *out of the authors* control. This behavior was introduced in #15954 and released as part of Ruff 0.9.5 (6th of February). There have been no new issues or PRs since this behavior change (preview) was introduced.
## Summary This PR stabilizes the preview behavior introduced in #15719 to recognize all symbols named `TYPE_CHECKING` as type-checking checks in `if TYPE_CHECKING` conditions. This ensures compatibility with mypy and pyright. This PR also stabilizes the new behavior that removes `if 0:` and `if False` to be no longer considered type checking blocks. Since then, this syntax has been removed from the typing spec and was only used for Python modules that don't have a `typing` module ([comment](#15719 (comment))). The preview behavior was first released with Ruff 0.9.5 (6th of February), which was about a month ago. There are no open issues or PRs for the changed behavior ## Test Plan The snapshots for `SIM108` change because `SIM108` ignored type checking blocks but it can no simplify `if 0` or `if False` blocks again because they're no longer considered type checking blocks. The changes in the `TC005` snapshot or only due to that `if 0` and `if False` are no longer recognized as type checking blocks <!-- How was it tested? -->
…P015`) (#16672) ## Summary This PR stabilizes the behavior change introduced in #15872 The diagnostic range is now the range of the redundant `mode` argument where it previously was the range of the entire `open` call: Before: ``` UP015.py:2:1: UP015 [*] Unnecessary mode argument | 1 | open("foo", "U") 2 | open("foo", "Ur") | ^^^^^^^^^^^^^^^^^ UP015 3 | open("foo", "Ub") 4 | open("foo", "rUb") | = help: Remove mode argument ``` Now: ``` UP015.py:2:13: UP015 [*] Unnecessary mode argument | 1 | open("foo", "U") 2 | open("foo", "Ur") | ^^^^ UP015 3 | open("foo", "Ub") 4 | open("foo", "rUb") | = help: Remove mode argument ``` This is a breaking change because it may require moving a `noqa` comment onto a different line, e.g if you have ```py open( "foo", "Ur", ) # noqa: UP015 ``` Needs to be rewritten to ```py open( "foo", "Ur", # noqa: UP015 ) ``` There have been now new issues or PRs since the new preview behavior was implemented. It first was released as part of Ruff 0.9.5 on the 5th of Feb (a little more than a month ago) ## Test Plan I reviewed the snapshot tests
## Summary This PR stabilizes the fixes improvements made in #15562 (released with ruff 0.9.3 in mid January). There's no open issue or PR related to the changed fix behavior. This is not a breaking change. The fix was only gated behind preview to get some more test coverage before releasing.
…6680) ## Summary Deprecate `S320` because defusedxml has deprecated there `lxml` module and `lxml` has been hardened since. flake8-bandit has removed their implementation as well (PyCQA/bandit#1212). Addresses #13707 ## Test Plan I verified that selecting `S320` prints a warning and fails if the preview mode is enabled.
…method-argument` and not `invalid-first-argument-name-for-class-method` (`PLW0211`/`N804`) (#16676) ## Summary This PR stabilizes the behavior changes introduced by #13305 that were gated behind preview. The change is that `__new__` methods are now no longer flagged by `invalid-first-argument-name-for-class-method` (`N804`) but instead by `bad-staticmethod-argument` (`PLW0211`) > __new__ methods are technically static methods, with cls as their first argument. However, Ruff currently classifies them as classmethod, which causes two issues: ## Test Plan There have been no new issues or PRs related to `N804` or `PLW0211` since the behavior change was released in Ruff 0.9.7 (about 3 weeks ago). This is a somewhat recent change but I don't think it's necessary to leave this in preview for another 2 months. The main reason why it was in preview is that it is breaking, not because it is a risky change.
…when all elements are hashable (`PLR1714`) (#16685) ## Summary This PR promotes the fix improvements for `PLR1714` that were introduced in #14372 to stable. The improvement is that the fix now proposes to use a set if all elements are hashable: ``` foo == "bar" or foo == "baz" or foo == "qux" ``` Gets fixed to ```py foo in {"bar", "baz", "qux"} ``` where it previously always got fixed to a tuple. The new fix was first released in ruff 0.8.0 (Nov last year). This is not a breaking change. The change was preview gated only to get some extra test coverage. There are no open issues or PRs related to this changed fix behavior.
## Summary This PR stabilizes the behavior introduced in #15985 The new behavior improves the inference of `str.strip` calls: * before: The rule only considered calls on string or byte literals (`"abcd".strip`) * now: The rule also catches calls to `strip` on object where the type is known to be a `str` or `bytes` (e.g. `a = "abc"; a.strip("//")`) The new behavior shipped as part of Ruff 0.9.6 on the 10th of Feb which is a little more than a month ago. There have been now new issues or PRs related to the new behavior.
72ffa12
to
851427a
Compare
Summary
Release branch for Ruff 0.10
printDebugInformation
command #16617flake8-builtins
] Removebuiltins-
prefix from option names #16092TYPE_CHECKING
symbols for type-checking blocks #16669requires-python
in certain cases whentarget-version
is not found #16319Recoded rules
flake8-bandit
] Moveunsafe-markup-use
fromRUF035
toS704
#15957Deprecated rules
pyupgrade
]: Deprecatenon-pep604-isinstance
(UP038
) #16681flake8-bandit
] Deprecatesuspicious-xmle-tree-usage
(S320
) #16680Rule changes
flake8-pyi
] Stabilize preview-mode behaviours forcustom-type-var-for-self
(PYI019
) #16607flake8-builtins
] Default to non-strict checking (A005
) #16125flake8-pytest-style
] Allow for loops with empty bodies (PT012
,PT031
) #16678pylint
] Detect invalid default value type foros.environ.get
(PLW1508
) #16674pep8-naming
]: Ignore methods decorated with@typing.override
(invalid-argument-name
) #16667pylint
] Better inference forstr.strip
(PLE310
) #16671pyupgrade
]: Improve diagnostic range forredundant-open-mode
(UP015
) #16672pylint
/pep8-naming
] Check__new__
argument name inbad-staticmethod-argument
and notinvalid-first-argument-name-for-class-method
(PLW0211
/N804
) #16676pygrep-hooks
]: Detect file-level suppressions comments without rule codes (PGH004
) #16699Rule Stabilizations
flake8-comprehensions
] Stabilizeunnecessary-dict-comprehension-for-iterable
(C420
) #16624FastAPI
] Stabilizefast-api-unused-path-parameter
(FAST003
) #16625pylint
] Stabilizelen-test
(PLC1802
) #16626pylint
] Stabilizeshallow-copy-environ
(PLW1507
) #16627flake8-simplify
] Stabilizesplit-static-string
(SIM905
) #16631pyupgrade
] Stabilizenon-pep646-unpack
(UP044
) #16632ruff
] Stabilizeif-key-in-dict-del
(RUF051
) #16658flake8-use-pathlib
] Stabilizeinvalid-pathlib-with-suffix
(PTH210
) #16656flake8-bugbear
] Stabilizebatched-without-explicit-strict
(B911
) #16655flake8-logging
] Stabilizeroot-logger-call
(LOG015
) #16654ruff
] Stabilizemap-int-version-parsing
(RUF048
) #16653ruff
] Stabilizeunnecessary-cast-to-int
(RUF046
) #16649ruff
] Stabilizeunnecessary-nested-literal
(RUF041
) #16648ruff
] Stabilizeinvalid-assert-message-literal-argument
(RUF040
) #16646flake8-bandit
] Stabilizeunsafe-markup-use
(S704
) #16643flake8-use-pathlib
] Stabilizeos-listdir
(PTH208
) #16642flake8-type-checking
] Stabilizeunquoted-type-alias
(TC007
) #16638flake8-type-checking
] Stabilizeruntime-cast-value
(TC006
) #16637flake8-datetimez
] Stabilizedatetime-min-max
(DTZ901
) #16635New or improved fixes
pylint
] Improverepeated-equality-comparison
fix to use aset
when all elements are hashable (PLR1714
) #16685flake8-simplify
] Avoid double negation in fixes (SIM103
) #16684flake8-pyi
] Stabilize fix forunused-private-type-var
(PYI018
) #16682Deferred Stabilizations
ruff
] Stabilizepytest-raises-ambiguous-pattern
(RUF043
) #16657ruff
] Stabilizeunraw-re-pattern
(RUF039
) #16644flake8-type-checking
] Stabilizequoted-type-alias
(TC008
) #16639TODOs