Skip to content

[flake8-simplify] Suppress SIM105 for except* before Python 3.12#23869

Merged
charliermarsh merged 5 commits intoastral-sh:mainfrom
getehen:fix/SIM105-disabled-py311
Mar 27, 2026
Merged

[flake8-simplify] Suppress SIM105 for except* before Python 3.12#23869
charliermarsh merged 5 commits intoastral-sh:mainfrom
getehen:fix/SIM105-disabled-py311

Conversation

@getehen
Copy link
Copy Markdown
Contributor

@getehen getehen commented Mar 10, 2026

Hi,

Fix 23798 : SIM105 should not be active before py 3.12.

The solution is simple: If the target version is lower or equal than 3.11, the check is passed.
There might be a caveat: I am not sure the target version is always 100% valid ? But it seemed the most accurate thing to use here.

Some tests were added, checking in 3.12 and 3.11 to check that the test suppression happen in 3.11 but not in 3.12.

I can also add a mention in the docs ? If so, should I do this directly here ?

@astral-sh-bot astral-sh-bot bot requested a review from ntBre March 10, 2026 14:59
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 10, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

ntBre
ntBre previously requested changes Mar 10, 2026
Copy link
Copy Markdown
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.

This fix doesn't appear to be correct. I checked the ecosystem report and regular except handlers (with just except) are no longer being flagged. The issue is specific to except* handlers like that shown in the issue:

def raise_group(x):
    raise ExceptionGroup("!", [ValueError(x)])
try:
   raise_group(1)
except* ValueError:  # This needs to be skipped
   pass

try: ...
except ValueError: # This should still emit a diagnostic
    pass

@getehen
Copy link
Copy Markdown
Contributor Author

getehen commented Mar 11, 2026

My bad, I will look into it

For py311, suppressible-exception should not be raised with except* (in
my previous commit I disabled it with every except, independently of the
*, which is wrong).

New tests accordingly.
Copy link
Copy Markdown
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! This looks good to me now, I just had one suggestion about testing.

Path::new("flake8_simplify").join(path).as_path(),
&settings::LinterSettings::for_rule(rule_code).with_target_version(py_version),
)?;
assert_diagnostics!(snapshot, diagnostics);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this would be a good use of our assert_diagnostics_diff! macro instead of two separate test_cases.

@ntBre ntBre changed the title [flake8-simplify] Make SIM105 invalid for py <= 3.11 [flake8-simplify] Suppress SIM105 for except* before Python 3.12 Mar 12, 2026
assert_diagnostic_diff is better than two test cases with a different
version
@getehen
Copy link
Copy Markdown
Contributor Author

getehen commented Mar 22, 2026

Sorry for the delay, it was indeed exactly what assert_diagnostics_diff was made for

@charliermarsh charliermarsh enabled auto-merge (squash) March 27, 2026 02:45
@charliermarsh charliermarsh disabled auto-merge March 27, 2026 02:51
@charliermarsh charliermarsh requested a review from ntBre March 27, 2026 02:51
@charliermarsh charliermarsh enabled auto-merge (squash) March 27, 2026 02:51
@charliermarsh charliermarsh disabled auto-merge March 27, 2026 02:51
@charliermarsh charliermarsh removed the request for review from ntBre March 27, 2026 02:52
@charliermarsh charliermarsh enabled auto-merge (squash) March 27, 2026 02:52
@charliermarsh charliermarsh merged commit 690ef81 into astral-sh:main Mar 27, 2026
42 checks passed
carljm added a commit that referenced this pull request Mar 31, 2026
* main: (40 commits)
  [ty] resolve union-likes in emitting union attribute errors (#24263)
  [ty] Improve support for `Callable` type context (#23888)
  [ty] Propagate type context through `await` expressions (#24256)
  [`pyflakes`] Flag annotated variable redeclarations as `F811` in preview mode (#24244)
  [ty] Preserve `Divergent` when materializing recursive aliases (#24245)
  Fix W391 fixes for consecutive empty notebook cells (#24236)
  [flake8-bugbear] Clarify RUF071 fix safety for non-path string comparisons (#24149)
  [ty] Ban type qualifiers in PEP-695 type aliases (#24242)
  [ty] Include keyword-prefixed symbols in completions for attributes (#24232)
  [ty] Add tests for TypedDict method overloads on unions (#24230)
  [ty] report unused bindings as unnecessary hint diagnostics (#23305)
  Remove unused `non_root` variable (#24238)
  Extend F507 to flag %-format strings with zero placeholders (#24215)
  [`flake8-simplify`] Suppress `SIM105` for `except*` before Python 3.12 (#23869)
  Ignore pre-initialization references in SIM113 (#24235)
  Parenthesize expression in RUF050 fix (#24234)
  Publish playgrounds using the `release-playground` environment (#24223)
  [ty] Fix instance-attribute lookup in methods of protocol classes (#24213)
  [ty] Used shared expression cache during generic call inference (#24219)
  [ty] make `Type::BoundMethod` include instances of same-named methods bound to a subclass (#24039)
  ...
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.

SIM105 should be suppressed for except* in Python 3.11

3 participants