Avoid class-scope name collisions in stubs#15994
Merged
JelleZijlstra merged 1 commit intoJul 11, 2026
Merged
Conversation
Class members such as list, type, cursor, Model, and datetime shadow the builtins, classes, or modules referenced by nearby annotations. ty then resolves those annotations to Unknown, which can hide invalid calls in APIs including docker, sqlite3, psycopg2, Markdown, and requests. Qualify shadowed builtins and use private aliases for colliding imports and classes. This removes 15 stdlib and 120 third-party collision diagnostics under ty 0.0.58, restores the affected public types, and fixes four existing psycopg2 type assertions.
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
carljm
approved these changes
Jul 10, 2026
srittau
approved these changes
Jul 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I tried running ty on the typeshed stubs, and most of the issues it flagged were due to name collisions in class scopes. These issues are of the form "class defines a method named
list, but also uses thelisttype". This PR fixes all of these collisions by using aliases or importing frombuiltins.In a followup PR I can start running ty on the stubs in CI, but since this change is already fairly large I figured I'd make it a separate PR.