Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[flake8-type-checking] Add sub-diagnostic showing the runtime use of an annotation (TC004)#23091

Merged
ntBre merged 2 commits intoastral-sh:mainfrom
11happy:add_subdiagnostic_TC004
Feb 6, 2026
Merged

[flake8-type-checking] Add sub-diagnostic showing the runtime use of an annotation (TC004)#23091
ntBre merged 2 commits intoastral-sh:mainfrom
11happy:add_subdiagnostic_TC004

Conversation

@11happy
Copy link
Contributor

@11happy 11happy commented Feb 5, 2026

Summary

Part of #17203, have not changed ImportBinding #16490 (comment)

Test Plan

Updated snapshots.

@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 5, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

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 for working on this! I'm obviously a bit biased, but I think I would overall prefer my patch from #16490 (comment). I'm not as worried about the runtime_reference field being unused by TC001-TC003 now, it seems fine for those rules to pass None.

&& !(ignore_dunder_all_references && reference.in_dunder_all_definition())
})
{
.collect();
Copy link
Contributor

Choose a reason for hiding this comment

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

The count field is a nice touch, but I don't think it's worth allocating a Vec here. I think flagging the first runtime reference with a secondary annotation is enough.

Ignore,
}

struct RuntimeInformation {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know I was the one who said

Storing this information in ImportBinding doesn't necessarily feel like the best approach

but I think I would still prefer my patch from #16490 (comment). This type doesn't seem to help all that much and also causes us to allocate several intermediate Vecs, at least in the current state of the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes I also felt the same, however I thought would try this approach , no worries I will refactor it similar to your patch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for exploring this! It was good to see another approach :)

@ntBre ntBre added the diagnostics Related to reporting of diagnostics. label Feb 5, 2026
@11happy 11happy force-pushed the add_subdiagnostic_TC004 branch from b49f668 to 6fceea1 Compare February 6, 2026 09:12
Signed-off-by: Bhuminjay <[email protected]>
@11happy
Copy link
Contributor Author

11happy commented Feb 6, 2026

done refactored to previous approach : )
while working on this I saw a todo mentioning #19359 I would be interested to work on that. if you have any specific pointers to keep in mind please let me know.
Thank you

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.

Nice, thank you!

Regarding #19359, I don't think I have any specific pointers besides checking what I did in #19100. I think I added a helper method or two that should be of use. Let me know if you run into any issues!

Ah, I guess one suggestion, I would probably start with either TC004 or TC010 instead of the UP rules since there's more of a design question around handling the UP and FA interaction.

@ntBre ntBre changed the title [ruff] add subdiagnostic for TC004 [flake8-type-checking] Add sub-diagnostic showing the runtime use of an annotation (TC004) Feb 6, 2026
@ntBre ntBre merged commit e84b0f4 into astral-sh:main Feb 6, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TC004 diagnostics/docs should clarify that type hints can be executed at run-time

2 participants