You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
We need equivalent of parse_type_string() in native parser #21515
This is needed to parse an arbitrary string as a type. This is especially important in context of TypeForm support (but is still needed in various other cases where we implicitly use old parser now, e.g. cast(), type alias targets etc).
Since we may make many calls to this function per file, overhead of using a Python call may be significant. We should probably consider adding a mypyc primitive for this that would use a capsule import from ast_serialize. It looks like PyO3 does support capsules, see https://docs.rs/pyo3/latest/pyo3/types/struct.PyCapsule.html
We can have a dedicated function in ast_serialize with a (much) simpler signature that also doesn't try to serialize imports etc.
I think having a separate fast alternative function with a simpler signature in ast_serialize would make sense, but we can run some microbencmark first to estimate how much of a bottleneck this is. Using a primitive seems unnecessary, since the function probably won't be called a huge number of times, and vectorcall overhead is mostly relevant for very tiny functions.
Activity
ilevkivskyi commentedon Aug 5, 2026
@JukkaL so coming back to this, do you with we should:
ast_serializefor this purpose, ormypywhen deserializing?JukkaL commentedon Aug 6, 2026
I think having a separate fast alternative function with a simpler signature in
ast_serializewould make sense, but we can run some microbencmark first to estimate how much of a bottleneck this is. Using a primitive seems unnecessary, since the function probably won't be called a huge number of times, and vectorcall overhead is mostly relevant for very tiny functions.Expose serialize_string_type() in public API (#86)
Use native parse_type_string() (#21965)