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

Skip to content

[ty] Avoid shadowing hints for attribute assignments#26164

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/fix-1990-shadowing-diagnostic
Jun 22, 2026
Merged

[ty] Avoid shadowing hints for attribute assignments#26164
charliermarsh merged 1 commit into
mainfrom
charlie/fix-1990-shadowing-diagnostic

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

invalid-assignment adds an implicit-shadowing hint when an assignment replaces a class or function binding. Prior to this change, the shared diagnostic construction also attached this hint to attribute assignments whose declared type happened to be a function, even though assigning an attribute does not shadow a name binding:

from configparser import ConfigParser

config = ConfigParser()
config.optionxform = str

This moves the shadowing-specific context to the general assignment path and only adds it for direct name targets. Invalid attribute assignments continue to report the assignability error, but no longer include misleading guidance about implicit shadowing. The existing diagnostics for direct class and function shadowing remain unchanged.

The regression snapshot covers the reported ConfigParser.optionxform case.

Closes astral-sh/ty#1990.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 19, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@charliermarsh charliermarsh marked this pull request as ready for review June 19, 2026 21:25
@charliermarsh charliermarsh requested a review from a team as a code owner June 19, 2026 21:25
@charliermarsh charliermarsh added the bug Something isn't working label Jun 19, 2026
@astral-sh-bot astral-sh-bot Bot requested a review from dcreager June 19, 2026 21:26
@astral-sh-bot

astral-sh-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh merged commit 55d1f44 into main Jun 22, 2026
60 checks passed
@charliermarsh charliermarsh deleted the charlie/fix-1990-shadowing-diagnostic branch June 22, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

don't emit diagnostics about "shadowing" when assignment target is not a local variable

1 participant