Skip to content

Conversation

@MatthewMckee4
Copy link
Contributor

Summary

Was just playing around with this, there's definitely more to do with this function, but it seems like maybe a better option than having so many arms in has_relation_to for (_, Callable).

Not super invested in this but wanting to hear opinions if people have time

@MatthewMckee4 MatthewMckee4 changed the title Add into_callable method for Type [ty] Add into_callable method for Type Jul 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2025

mypy_primer results

Changes were detected when running on open source projects
mypy_primer (https://github.com/hauntsaninja/mypy_primer)
-     memo fields = ~45MB
+     memo fields = ~41MB

aioredis (https://github.com/aio-libs/aioredis)
-     memo fields = ~54MB
+     memo fields = ~60MB

operator (https://github.com/canonical/operator)
- TOTAL MEMORY USAGE: ~106MB
+ TOTAL MEMORY USAGE: ~97MB
-     memo fields = ~88MB
+     memo fields = ~80MB

pydantic (https://github.com/pydantic/pydantic)
- TOTAL MEMORY USAGE: ~142MB
+ TOTAL MEMORY USAGE: ~156MB

mkdocs (https://github.com/mkdocs/mkdocs)
- TOTAL MEMORY USAGE: ~129MB
+ TOTAL MEMORY USAGE: ~117MB

tornado (https://github.com/tornadoweb/tornado)
- TOTAL MEMORY USAGE: ~156MB
+ TOTAL MEMORY USAGE: ~171MB

werkzeug (https://github.com/pallets/werkzeug)
-     memo fields = ~129MB
+     memo fields = ~142MB

psycopg (https://github.com/psycopg/psycopg)
- TOTAL MEMORY USAGE: ~207MB
+ TOTAL MEMORY USAGE: ~228MB

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Jul 3, 2025
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I think it's exactly the direction we want to head in, as it will make subtyping/assignability between various types and protocols with __call__ methods easier too.

@MatthewMckee4
Copy link
Contributor Author

Seems like they're caught in mypy primer, ill make them return None but add a todo comment

Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you!

cc @abhijeetbodas2001, I think my review comments on your returns-Never PR mentioned wanting this method.

@carljm carljm merged commit 3be83d3 into astral-sh:main Jul 4, 2025
35 checks passed
@MatthewMckee4 MatthewMckee4 deleted the into-callable branch July 16, 2025 21:12
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.

3 participants