Skip to content

Conversation

@carljm
Copy link
Contributor

@carljm carljm commented May 22, 2025

Summary

Fix some issues with subtying/assignability for instances vs callables. We need to look up dunders on the class, not the instance, and we should limit our logic here to delegating to the type of __call__, so it doesn't get out of sync with the calls we allow.

Also, we were just entirely missing assignability handling for __call__ implemented as anything other than a normal bound method (though we had it for subtyping.)

A first step towards considering what else we want to change in astral-sh/ty#491

Test Plan

mdtests

Co-authored-by: med <medioqrity@gmail.com>
@github-actions
Copy link
Contributor

mypy_primer results

Changes were detected when running on open source projects
strawberry (https://github.com/strawberry-graphql/strawberry)
- error[invalid-assignment] strawberry/federation/scalar.py:133:9: Object of type `_T | None` is not assignable to `((...) -> Unknown) | None`
- error[invalid-argument-type] strawberry/types/scalar.py:110:29: Argument to bound method `__init__` is incorrect: Expected `(Any, /) -> Any`, found `_T`
- error[invalid-assignment] strawberry/types/scalar.py:209:9: Object of type `_T | None` is not assignable to `((...) -> Unknown) | None`
- Found 436 diagnostics
+ Found 433 diagnostics

jinja (https://github.com/pallets/jinja)
- error[invalid-argument-type] src/jinja2/ext.py:168:27: Argument to bound method `call` is incorrect: Expected `(...) -> Any`, found `Any | Undefined`
- Found 234 diagnostics
+ Found 233 diagnostics

carljm and others added 3 commits May 22, 2025 15:28
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@carljm carljm enabled auto-merge (squash) May 22, 2025 19:44
@carljm carljm merged commit 0b181bc into main May 22, 2025
30 checks passed
@carljm carljm deleted the cjm/callable-instances branch May 22, 2025 19:47
carljm added a commit that referenced this pull request May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants