Skip to content

[pyupgrade] Enable rule triggering for stub files (UP043)#20027

Merged
dylwil3 merged 4 commits intoastral-sh:mainfrom
IDrokin117:feat/ruff-20011
Sep 9, 2025
Merged

[pyupgrade] Enable rule triggering for stub files (UP043)#20027
dylwil3 merged 4 commits intoastral-sh:mainfrom
IDrokin117:feat/ruff-20011

Conversation

@IDrokin117
Copy link
Contributor

Summary

Resolves #20011

Implemented alternative triggering condition for rule UP043 based on requirements outlined in issue #20011

Test Plan

Created .pyi file to ensure triggering the rule

@github-actions
Copy link
Contributor

github-actions bot commented Aug 21, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+265 -0 violations, +0 -0 fixes in 2 projects; 53 projects unchanged)

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

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

+ providers/common/sql/src/airflow/providers/common/sql/hooks/sql.pyi:112:10: UP043 [*] Unnecessary default type arguments
+ providers/common/sql/src/airflow/providers/common/sql/hooks/sql.pyi:146:10: UP043 [*] Unnecessary default type arguments
+ providers/common/sql/src/airflow/providers/common/sql/hooks/sql.pyi:156:10: UP043 [*] Unnecessary default type arguments

python/typeshed (+262 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select E,F,FA,I,PYI,RUF,UP,W

+ stdlib/argparse.pyi:315:60: UP043 [*] Unnecessary default type arguments
+ stdlib/codecs.pyi:198:83: UP043 [*] Unnecessary default type arguments
+ stdlib/codecs.pyi:199:85: UP043 [*] Unnecessary default type arguments
+ stdlib/concurrent/futures/process.pyi:100:53: UP043 [*] Unnecessary default type arguments
+ stdlib/email/message.pyi:133:23: UP043 [*] Unnecessary default type arguments
+ stdlib/lib2to3/fixes/fix_except.pyi:9:42: UP043 [*] Unnecessary default type arguments
+ stdlib/lib2to3/fixes/fix_import.pyi:8:32: UP043 [*] Unnecessary default type arguments
+ stdlib/lib2to3/fixes/fix_imports.pyi:11:35: UP043 [*] Unnecessary default type arguments
+ stdlib/lib2to3/fixes/fix_metaclass.pyi:11:29: UP043 [*] Unnecessary default type arguments
+ stdlib/lib2to3/fixes/fix_renames.pyi:10:24: UP043 [*] Unnecessary default type arguments
+ stdlib/lib2to3/fixes/fix_urllib.pyi:8:24: UP043 [*] Unnecessary default type arguments
+ stdlib/lib2to3/refactor.pyi:72:10: UP043 [*] Unnecessary default type arguments
+ stdlib/lib2to3/refactor.pyi:73:63: UP043 [*] Unnecessary default type arguments
+ stdlib/pathlib/__init__.pyi:183:80: UP043 [*] Unnecessary default type arguments
+ stdlib/pathlib/__init__.pyi:184:81: UP043 [*] Unnecessary default type arguments
+ stdlib/pathlib/__init__.pyi:186:41: UP043 [*] Unnecessary default type arguments
+ stdlib/pathlib/__init__.pyi:187:42: UP043 [*] Unnecessary default type arguments
+ stdlib/pathlib/__init__.pyi:202:26: UP043 [*] Unnecessary default type arguments
+ stdlib/sqlite3/__init__.pyi:367:61: UP043 [*] Unnecessary default type arguments
+ stdlib/sqlite3/__init__.pyi:369:31: UP043 [*] Unnecessary default type arguments
+ stdlib/tokenize.pyi:154:60: UP043 [*] Unnecessary default type arguments
+ stdlib/tokenize.pyi:155:53: UP043 [*] Unnecessary default type arguments
+ stdlib/traceback.pyi:114:90: UP043 [*] Unnecessary default type arguments
+ stdlib/traceback.pyi:235:96: UP043 [*] Unnecessary default type arguments
+ stdlib/traceback.pyi:237:52: UP043 [*] Unnecessary default type arguments
+ stdlib/traceback.pyi:240:90: UP043 [*] Unnecessary default type arguments
+ stdlib/traceback.pyi:242:44: UP043 [*] Unnecessary default type arguments
+ stdlib/xml/etree/ElementPath.pyi:11:72: UP043 [*] Unnecessary default type arguments
+ stdlib/xml/etree/ElementPath.pyi:14:80: UP043 [*] Unnecessary default type arguments
+ stdlib/xml/etree/ElementPath.pyi:35:90: UP043 [*] Unnecessary default type arguments
+ stdlib/xml/etree/ElementTree.pyi:109:47: UP043 [*] Unnecessary default type arguments
+ stdlib/xml/etree/ElementTree.pyi:113:80: UP043 [*] Unnecessary default type arguments
+ stdlib/xml/etree/ElementTree.pyi:114:27: UP043 [*] Unnecessary default type arguments
+ stdlib/xml/etree/ElementTree.pyi:161:47: UP043 [*] Unnecessary default type arguments
+ stdlib/xml/etree/ElementTree.pyi:171:80: UP043 [*] Unnecessary default type arguments
+ stubs/JACK-Client/jack/__init__.pyi:240:39: UP043 [*] Unnecessary default type arguments
+ stubs/PyScreeze/pyscreeze/__init__.pyi:111:6: UP043 [*] Unnecessary default type arguments
+ stubs/PyScreeze/pyscreeze/__init__.pyi:123:6: UP043 [*] Unnecessary default type arguments
+ stubs/PyScreeze/pyscreeze/__init__.pyi:205:6: UP043 [*] Unnecessary default type arguments
+ stubs/PyScreeze/pyscreeze/__init__.pyi:217:6: UP043 [*] Unnecessary default type arguments
+ stubs/Pygments/pygments/filters/__init__.pyi:10:26: UP043 [*] Unnecessary default type arguments
+ stubs/Pygments/pygments/formatters/__init__.pyi:22:29: UP043 [*] Unnecessary default type arguments
+ stubs/Pygments/pygments/plugin.pyi:24:29: UP043 [*] Unnecessary default type arguments
+ stubs/Pygments/pygments/plugin.pyi:25:33: UP043 [*] Unnecessary default type arguments
+ stubs/Pygments/pygments/plugin.pyi:26:29: UP043 [*] Unnecessary default type arguments
+ stubs/Pygments/pygments/plugin.pyi:27:30: UP043 [*] Unnecessary default type arguments
+ stubs/antlr4-python3-runtime/antlr4/ParserRuleContext.pyi:32:46: UP043 [*] Unnecessary default type arguments
+ stubs/antlr4-python3-runtime/antlr4/RuleContext.pyi:26:30: UP043 [*] Unnecessary default type arguments
+ stubs/assertpy/assertpy/assertpy.pyi:64:26: UP043 [*] Unnecessary default type arguments
... 213 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
UP043 265 265 0 0 0

@dylwil3
Copy link
Collaborator

dylwil3 commented Aug 25, 2025

This looks right to me but since there's (necessarily) such a huge diff in the ecosystem it would be great if e.g. @AlexWaygood could confirm it's all good (and shouldn't be in preview)?

@ntBre ntBre added the rule Implementing or modifying a lint rule label Aug 25, 2025
@IDrokin117
Copy link
Contributor Author

@AlexWaygood Could you please review PR?

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.

Thanks! I just had a couple of nits but otherwise I agree with Dylan. This looks good, but I'd like to get quick confirmation from Alex that it makes sense to apply this rule to stubs. I think that's the case based on his comment here but good to double check.

I also think this should probably be a preview change. It's a straightforward code fix, but expanding the scope of the rule to a new file type seems pretty significant to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for identifying one of the files from the issue! However, I'd probably lean toward a stripped-down example over including a file verbatim from another project since the specifics of the code aren't really that important. We could even just duplicate UP043.py and call it UP043.pyi, I think.

/// ## What it does
/// Checks for unnecessary default type arguments for `Generator` and
/// `AsyncGenerator` on Python 3.13+.
/// `AsyncGenerator` on Python 3.13+ or stubs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// `AsyncGenerator` on Python 3.13+ or stubs.
/// `AsyncGenerator` on Python 3.13+ or in stubs.

@AlexWaygood
Copy link
Member

Yup, it makes sense for this to always be enabled for stubs regardless of Python version.

I agree with Brent that this should probably be gated behind preview initially. The change was requested by a typeshed maintainer, and I'm also a typeshed maintainer, so I wouldn't worry too much about the impact on typeshed (it's not going to take us by surprise! 😄) -- but there are other authors of stubs out there, and it could take them by surprise to have such a big expansion of the rule go directly into a stable rule without a preview-only period first.

@AlexWaygood
Copy link
Member

(Sorry for the delayed response -- been a bit busy recently with a house move and other things!)

@IDrokin117
Copy link
Contributor Author

@AlexWaygood Thanks!
@ntBre I've gated changes behind preview.

@dylwil3 dylwil3 enabled auto-merge (squash) September 9, 2025 12:54
@dylwil3 dylwil3 merged commit 79706a2 into astral-sh:main Sep 9, 2025
34 checks passed
second-ed pushed a commit to second-ed/ruff that referenced this pull request Sep 9, 2025
…-sh#20027)

## Summary
Resolves astral-sh#20011

Implemented alternative triggering condition for rule
[`UP043`](https://docs.astral.sh/ruff/rules/unnecessary-default-type-args/)
based on requirements outlined in [issue
astral-sh#20011](astral-sh#20011)
## Test Plan
Created .pyi file to ensure triggering the rule

---------

Co-authored-by: Igor Drokin <drokinii1017@gmail.com>
Co-authored-by: dylwil3 <dylwil3@gmail.com>
ntBre added a commit that referenced this pull request Jan 30, 2026
ntBre added a commit that referenced this pull request Jan 30, 2026
ntBre added a commit that referenced this pull request Feb 3, 2026
ntBre added a commit that referenced this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unnecessary-default-type-args (UP043) isn't triggering on stubs on Python <3.13

4 participants