Skip to content

Conversation

@danparizher
Copy link
Contributor

Summary

Fixes #20341

@github-actions
Copy link
Contributor

github-actions bot commented Sep 11, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+6 -0 violations, +0 -0 fixes in 4 projects; 51 projects unchanged)

apache/superset (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

+ superset/commands/database/tables.py:143:34: SIM910 [*] Use `extra_dict_by_name.get(table.table)` instead of `extra_dict_by_name.get(table.table, None)`

binary-husky/gpt_academic (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ request_llms/bridge_all.py:1304:31: SIM910 [*] Use `dict.get()` without default value

zulip/zulip (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

+ zerver/models/users.py:736:28: SIM910 [*] Use `user_data.get(field.id)` instead of `user_data.get(field.id, None)`
+ zerver/tornado/event_queue.py:1231:49: SIM910 [*] Use `extra_user_data.get(client.user_profile_id)` instead of `extra_user_data.get(client.user_profile_id, None)`

astropy/astropy (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ astropy/table/mixins/registry.py:66:16: SIM910 [*] Use `dict.get()` without default value
+ astropy/wcs/wcsapi/fitswcs.py:287:34: SIM910 [*] Use `CTYPE_TO_UCD1.get(ctype_name.upper())` instead of `CTYPE_TO_UCD1.get(ctype_name.upper(), None)`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
SIM910 6 6 0 0 0

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 hassle, but could you preview gate this too? This is a pretty big expansion in scope since it was restricted to only two types of expressions before.

@ntBre ntBre added rule Implementing or modifying a lint rule preview Related to preview mode features labels Sep 11, 2025
@danparizher danparizher requested a review from ntBre September 11, 2025 22:58
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! I just pushed one quick commit recombining the two test files. It makes it a little easier to stabilize later if we're already running the tests on both stable and preview.

# Complex expression as key
ages = {"Tom": 23, "Maria": 23, "Dog": 11}
key = "Tom" if True else "Maria"
age = ages.get(key, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually just another Expr::Name as key since it's assigned to a variable. Even the if expression itself is only a single Expr::If, but this is fine either way!

Copy link
Contributor

Choose a reason for hiding this comment

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

(I inlined this too while I was at it)

@ntBre ntBre changed the title [flake8-simplify] Detect unnecessary None default when key is a method call (SIM910) [flake8-simplify] Detect unnecessary None default for additional key expression types (SIM910) Sep 12, 2025
@ntBre ntBre merged commit 7be11b4 into astral-sh:main Sep 12, 2025
35 checks passed
@danparizher danparizher deleted the fix-20341 branch September 12, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIM910 doesn't recognize get access on dictionary when the key is a property/method call

2 participants