Skip to content

Avoid class-scope name collisions in stubs#15994

Merged
JelleZijlstra merged 1 commit into
python:mainfrom
jelle-openai:jelle/ty-typeshed-name-collisions
Jul 11, 2026
Merged

Avoid class-scope name collisions in stubs#15994
JelleZijlstra merged 1 commit into
python:mainfrom
jelle-openai:jelle/ty-typeshed-name-collisions

Conversation

@jelle-openai

Copy link
Copy Markdown
Contributor

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 the list type". This PR fixes all of these collisions by using aliases or importing from builtins.

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.

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.
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 6789530 into python:main Jul 11, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants