Skip to content

Conversation

@AlexWaygood
Copy link
Member

Summary

#20165 added a lot of false positives around calls to builtins.open(), because our missing support for PEP-613 type aliases means that we don't understand typeshed's overloads for builtins.open() at all yet, and therefore always select the first overload. This didn't use to matter very much, but now that we have a much stricter implementation of protocol assignability/subtyping it matters a lot, because most of the stdlib functions dealing with I/O (pickle, marshal, io, json, etc.) are annotated in typeshed as taking in protocols of some kind.

In lieu of full PEP-613 support, which is blocked on various things and might not land in time for our next alpha release, this PR adds some temporary special-casing for builtins.open() to avoid the false positives. We just infer Todo for anything that isn't meant to match typeshed's first open() overload. This should be easy to rip out again once we have proper support for PEP-613 type aliases, which hopefully should be pretty soon!

Test Plan

Added an mdtest

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Sep 12, 2025
@github-actions
Copy link
Contributor

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@github-actions
Copy link
Contributor

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-argument-type 0 55 0
invalid-assignment 0 8 0
no-matching-overload 0 8 0
invalid-return-type 0 7 0
unresolved-attribute 0 2 0
possibly-unbound-attribute 0 1 0
unused-ignore-comment 1 0 0
Total 1 81 0

Full report with detailed diff

@AlexWaygood
Copy link
Member Author

That looks like the kind of ecosystem report I expected!

@AlexWaygood AlexWaygood marked this pull request as ready for review September 12, 2025 17:44
@AlexWaygood
Copy link
Member Author

(The mypy_primer panic on sympy is happening on multiple PRs right now so is almost certainly unrelated)

@AlexWaygood AlexWaygood merged commit 1745554 into main Sep 12, 2025
39 of 40 checks passed
@AlexWaygood AlexWaygood deleted the alex/fix-open-false-positives branch September 12, 2025 21:20
@AlexWaygood
Copy link
Member Author

This just reduces the fallout of a change that's unreleased, so I'll add the internal label to keep it out of the changelog

@AlexWaygood AlexWaygood added the internal An internal refactor or improvement label Sep 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem-analyzer internal An internal refactor or improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants