Skip to content

[refurb] Check for subclasses includes subscript expressions (FURB189)#16155

Merged
MichaReiser merged 2 commits intoastral-sh:mainfrom
vladNed:bugfix/furb-189-rule-not-applied-when-type-args-provided
Feb 14, 2025
Merged

[refurb] Check for subclasses includes subscript expressions (FURB189)#16155
MichaReiser merged 2 commits intoastral-sh:mainfrom
vladNed:bugfix/furb-189-rule-not-applied-when-type-args-provided

Conversation

@vladNed
Copy link
Copy Markdown
Contributor

@vladNed vladNed commented Feb 14, 2025

Summary

Added checks for subscript expressions on builtin classes as in FURB189.
The object is changed to use the collections objects and the types from the subscript are kept.

Resolves #16130

Note: Added some comments in the code explaining why

Test Plan

  • Added a subscript dict and list class to the test file.
  • Tested locally to check that the symbols are changed and the types are kept.
  • No modifications changed on optional str values.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 14, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

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

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

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

+ dev/breeze/src/airflow_breeze/utils/selective_checks.py:136:20: FURB189 Subclassing `dict` can be error prone, use `collections.UserDict` instead

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/db_engine_specs/trino.py:407:30: FURB189 Subclassing `dict` can be error prone, use `collections.UserDict` instead

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

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

+ src/bokeh/util/compiler.py:73:16: FURB189 Subclassing `dict` can be error prone, use `collections.UserDict` instead
+ src/typings/bs4.pyi:12:17: FURB189 Subclassing `list` can be error prone, use `collections.UserList` instead

langchain-ai/langchain (+1 -0 violations, +0 -0 fixes)

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

+ libs/core/langchain_core/runnables/utils.py:465:19: FURB189 Subclassing `dict` can be error prone, use `collections.UserDict` instead

reflex-dev/reflex (+2 -0 violations, +0 -0 fixes)

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

+ tests/units/utils/test_types.py:50:18: FURB189 Subclassing `dict` can be error prone, use `collections.UserDict` instead
+ tests/units/vars/test_base.py:9:18: FURB189 Subclassing `dict` can be error prone, use `collections.UserDict` instead

python-trio/trio (+1 -0 violations, +0 -0 fixes)

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

+ src/trio/_core/_instrumentation.py:24:19: FURB189 Subclassing `dict` can be error prone, use `collections.UserDict` instead

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
FURB189 8 8 0 0 0

Comment thread crates/ruff_linter/src/rules/refurb/rules/subclass_builtin.rs Outdated
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Nice. I've a small nit comment but that otherwise looks good to go.

@MichaReiser MichaReiser added rule Implementing or modifying a lint rule preview Related to preview mode features labels Feb 14, 2025
@vladNed vladNed requested a review from MichaReiser February 14, 2025 18:14
@MichaReiser MichaReiser merged commit 2197128 into astral-sh:main Feb 14, 2025
@vladNed vladNed deleted the bugfix/furb-189-rule-not-applied-when-type-args-provided branch February 15, 2025 03:38
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.

(🐞) subclass-builtin (FURB189) doesn't apply when type arguments are supplied

2 participants