ruff/crates/ty_python_semantic/resources/mdtest/call
Alex Waygood 1745554809
[ty] Temporary hack to reduce false positives around builtins.open() (#20367)
## Summary

https://github.com/astral-sh/ruff/pull/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
2025-09-12 22:20:38 +01:00
..
annotation.md ty_python_semantic: add union type context to function call type errors 2025-05-09 13:40:51 -04:00
builtins.md [ty] Temporary hack to reduce false positives around builtins.open() (#20367) 2025-09-12 22:20:38 +01:00
callable_instance.md ty_python_semantic: add union type context to function call type errors 2025-05-09 13:40:51 -04:00
constructor.md [ty] Rename call-possibly-unbound-method to possibly-unbound-implicit-call (#18017) 2025-05-22 15:25:51 +00:00
dunder.md [ty] Allow declared-only class-level attributes to be accessed on the class (#19071) 2025-07-02 18:03:56 +02:00
dunder_import.md [ty] Add special-cased inference for __import__(name) and importlib.import_module(name) (#19008) 2025-06-29 11:49:23 +01:00
function.md [ty] Retry parameter matching for argument type expansion (#20153) 2025-09-12 08:40:07 +00:00
getattr_static.md [ty] eliminate is_fully_static (#18799) 2025-06-24 18:02:05 -07:00
invalid_syntax.md ty_python_semantic: add union type context to function call type errors 2025-05-09 13:40:51 -04:00
methods.md [ty] Ensure various special-cased builtin functions are understood as assignable to Callable (#20331) 2025-09-10 19:03:33 +00:00
never.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
overloads.md [ty] Retry parameter matching for argument type expansion (#20153) 2025-09-12 08:40:07 +00:00
replace.md [ty] synthesize __replace__ for dataclasses (>=3.13) (#19545) 2025-07-29 17:32:01 +02:00
str_startswith.md [ty] "foo".startswith is not an instance of types.MethodWrapperType (#20317) 2025-09-10 11:14:26 +00:00
subclass_of.md [ty] Include synthesized arguments in displayed counts for too-many-positional-arguments (#18098) 2025-05-14 22:51:23 -04:00
union.md [ty] eliminate is_fully_static (#18799) 2025-06-24 18:02:05 -07:00