Skip to content

Conversation

@TaKO8Ki
Copy link
Contributor

@TaKO8Ki TaKO8Ki commented Oct 4, 2025

Summary

Fixes #18778

Prevent SIM911 from triggering when zip() is called on .keys()/.values() that take any positional or keyword arguments, so Ruff
never suggests the lossy rewrite.

Test Plan

Added a test case to SIM911.py.

Comment on lines +87 to +92
if var1.id != var2.id
|| attr1 != "keys"
|| attr2 != "values"
|| !args1.is_empty()
|| !args2.is_empty()
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially thought I have to modify SIM911 to skip only the autofix, but I found a similar implementation here and aligned with that instead. If you’d prefer we go with it, I can update the implementation accordingly.

if !(args.is_empty() && keywords.is_empty()) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Either way works, I guess it makes sense to be consistent with the other SIM rule.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre added the bug Something isn't working label Oct 7, 2025
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Thank you! Sorry for the delay

Comment on lines +87 to +92
if var1.id != var2.id
|| attr1 != "keys"
|| attr2 != "values"
|| !args1.is_empty()
|| !args2.is_empty()
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Either way works, I guess it makes sense to be consistent with the other SIM rule.

@ntBre ntBre changed the title [ruff] Skip SIM911 when keys/values take arguments [flake8-simplify] Skip SIM911 when unknown arguments are present Oct 21, 2025
@ntBre ntBre merged commit a51a0f1 into astral-sh:main Oct 21, 2025
37 checks passed
dcreager added a commit that referenced this pull request Oct 22, 2025
* main: (65 commits)
  [ty] Some more simplifications when rendering constraint sets (#21009)
  [ty] Make `attributes.md` mdtests faster (#21030)
  [ty] Set `INSTA_FORCE_PASS` and `INSTA_OUTPUT` environment variables from mdtest.py (#21029)
  [ty] Fall back to `Divergent` for deeply nested specializations (#20988)
  [`ruff`] Autogenerate TypeParam nodes (#21028)
  [ty] Add assertions to ensure that we never call `KnownClass::Tuple.to_instance()` or similar (#21027)
  [`ruff`] Auto generate ast Pattern nodes (#21024)
  [`flake8-simplify`] Skip `SIM911` when unknown arguments are present (#20697)
  Render a diagnostic for syntax errors introduced in formatter tests (#21021)
  [ty] Support goto-definition on vendored typeshed stubs (#21020)
  [ty] Implement go-to for binary and unary operators (#21001)
  [ty] Avoid ever-growing default types (#20991)
  [syntax-errors] Name is parameter and global (#20426)
  [ty] Disable panicking mdtest (#21016)
  [ty] Fix completions at end of file (#20993)
  [ty] Fix out-of-order semantic token for function with regular argument after kwargs (#21013)
  [ty] Fix auto import for files with `from __future__` import (#20987)
  [`fastapi`] Handle ellipsis defaults in FAST002 autofix (`FAST002`) (#20810)
  [`ruff`] Skip autofix for keyword and `__debug__` path params (#20960)
  [`flake8-bugbear`] Skip `B905` and `B912` if <2 iterables and no starred arguments (#20998)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flake8-simplify] SIM911 false positive when methods have args

2 participants