Skip to content

[flake8-pyi] Extend PYI033 to Python files in preview#26129

Merged
AlexWaygood merged 1 commit into
mainfrom
codex/pyi033-preview-python-files
Jun 18, 2026
Merged

[flake8-pyi] Extend PYI033 to Python files in preview#26129
AlexWaygood merged 1 commit into
mainfrom
codex/pyi033-preview-python-files

Conversation

@AlexWaygood

@AlexWaygood AlexWaygood commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

This PR revives #4166.

There's no reason to use type comments in modern Python code. I'd argue they're effectively soft-deprecated at this point, and they're entirely unsupported by modern type checkers such as ty and pyrefly. In the three years since the last PR proposing this change, Python 2 has become much less widely used in the ecosystem, and many other flake8-pyi rules have been extended so that they now run on .py files as well.

If you enable strict mode in pyright, it enables pyright's reportTypeCommentUsage rule, which bans the use of type comments. I don't want to have to reimplement that rule in ty for pyright parity, when we already have a very good implementation over here in Ruff ;)

#1619 (comment) pointed out that there are still uses for type comments for things like for loops, e.g.

from models import Wheel

for wheel in car.wheels.all():  # type: Wheel
    ...

But even here, while it's not quite as pretty, mypy users can easily use modern type annotations instead:

from models import Wheel

wheel: Wheel
for wheel in car.wheels.all():
    ...

Closes #4460

@AlexWaygood AlexWaygood added rule Implementing or modifying a lint rule preview Related to preview mode features labels Jun 18, 2026
@AlexWaygood AlexWaygood marked this pull request as ready for review June 18, 2026 14:30
@astral-sh-bot astral-sh-bot Bot requested a review from ntBre June 18, 2026 14:30
@astral-sh-bot

astral-sh-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

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

PlasmaPy/PlasmaPy (+11 -0 violations, +0 -0 fixes)

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

+ src/plasmapy/analysis/fit_functions.py:35:36: type-comment-in-stub Don't use type comments
+ tests/analysis/test_fit_functions.py:66:36: type-comment-in-stub Don't use type comments
+ tests/analysis/test_fit_functions.py:67:42: type-comment-in-stub Don't use type comments
+ tests/analysis/test_fit_functions.py:68:41: type-comment-in-stub Don't use type comments
+ tests/analysis/test_fit_functions.py:69:39: type-comment-in-stub Don't use type comments
+ tests/analysis/test_fit_functions.py:70:36: type-comment-in-stub Don't use type comments
+ tests/utils/decorators/test_checks.py:66:62: type-comment-in-stub Don't use type comments
+ tests/utils/decorators/test_checks.py:785:64: type-comment-in-stub Don't use type comments
+ tests/utils/decorators/test_validators.py:164:12: type-comment-in-stub Don't use type comments
+ tests/utils/decorators/test_validators.py:27:67: type-comment-in-stub Don't use type comments
+ tests/utils/decorators/test_validators.py:28:70: type-comment-in-stub Don't use type comments

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

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

+ performance/src/performance_dags/performance_dag/performance_dag.py:131:5: type-comment-in-stub Don't use type comments
+ performance/src/performance_dags/performance_dag/performance_dag.py:149:5: type-comment-in-stub Don't use type comments
+ performance/src/performance_dags/performance_dag/performance_dag.py:182:5: type-comment-in-stub Don't use type comments
+ performance/src/performance_dags/performance_dag/performance_dag.py:71:5: type-comment-in-stub Don't use type comments
+ performance/src/performance_dags/performance_dag/performance_dag.py:84:5: type-comment-in-stub Don't use type comments
+ performance/src/performance_dags/performance_dag/performance_dag_utils.py:641:5: type-comment-in-stub Don't use type comments
+ performance/src/performance_dags/performance_dag/performance_dag_utils.py:679:5: type-comment-in-stub Don't use type comments
+ providers/google/src/airflow/providers/google/cloud/operators/bigtable.py:299:45: type-comment-in-stub Don't use type comments
+ providers/google/src/airflow/providers/google/cloud/operators/bigtable.py:362:56: type-comment-in-stub Don't use type comments
+ providers/google/src/airflow/providers/google/cloud/operators/bigtable.py:474:56: type-comment-in-stub Don't use type comments
+ providers/google/src/airflow/providers/google/cloud/operators/bigtable.py:49:31: type-comment-in-stub Don't use type comments
+ providers/google/src/airflow/providers/google/cloud/operators/bigtable.py:541:67: type-comment-in-stub Don't use type comments

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

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

+ superset/db_engine_specs/ocient.py:100:14: type-comment-in-stub Don't use type comments
+ superset/db_engine_specs/ocient.py:113:13: type-comment-in-stub Don't use type comments
+ superset/db_engine_specs/ocient.py:126:18: type-comment-in-stub Don't use type comments
+ superset/db_engine_specs/ocient.py:151:15: type-comment-in-stub Don't use type comments
+ tests/integration_tests/superset_test_custom_template_processors.py:43:62: type-comment-in-stub Don't use type comments

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
type-comment-in-stub 28 28 0 0 0

@AlexWaygood

Copy link
Copy Markdown
Member Author

All the ecosystem hits look like true positives to me

@ntBre

ntBre commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

I guess we might need to rename the rule eventually?

@AlexWaygood AlexWaygood merged commit b83c024 into main Jun 18, 2026
45 checks passed
@AlexWaygood AlexWaygood deleted the codex/pyi033-preview-python-files branch June 18, 2026 15:13
@MichaReiser

MichaReiser commented Jun 18, 2026

Copy link
Copy Markdown
Member

type-comment-in-stub Don't use type comments

Do we need to change the rule name (This is not a breaking change yet)

@AlexWaygood

Copy link
Copy Markdown
Member Author

Shoot, I merged before seeing your comments. I'll rename it in a followup.

@MichaReiser

Copy link
Copy Markdown
Member

Renaming in a follow up seems preferred anyway :)

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.

new rule - ban legacy # type: comments (ANN402)

3 participants