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
The typing module needs to be updated to 3.12. It seems that it was last updated to 3.9, so it's missing several major versions worth of features, like Unpack, generics, and type aliases using the type keyword.
Not having these typing features impedes the process of updating modules that use, which presumably will be most new stuff going forward.
I estimate that updating will require:
Moving some abstract base classes from typing.py into a new native module typing.rs, specifically TypeVar, ParamSpec, TypeVarTuple, ParamSpecArgs, ParamSpecKwards, TypeAliasType, and Generic.
Adding new instructions which generate/consume type information to compiler.rs and frame.rs. For example, def foo[T](x: T): ... must create a new TypeVar(T) and inject it into the correct scope so that it is available as an argument annotation. This requires a new instruction defined in bytecode.rs which is emitted by compiler.rs and consumed by frame.rs.
Copying typing.py and test_typing.py from the CPython code base.
Python Documentation or reference to CPython source code
I've been chewing on this for a bit, but it's pretty slow going since I'm also learning about a lot of compilation internals. As soon as I have something that is mostly compatible with the 3.12 typing.py I will submit a partial PR to get some incremental feedback.
I don't know if this is already known, but I just wanted to add to the 3.12 typing discussion that if not running in release mode, syntax like def foo[T](): pass causes a panic in the parser at core/src/source_code.rs:139:9
@hbina Hi, open Lib/test/test_typing.py in RustPython source code and search # TODO: RUSTPYTHON in the file. You will find many failing tests from there. Removing one of them will make cargo run -- Lib/test/test_typing.py be failed. That's the starting point.
Activity
dchiquito commentedon Apr 22, 2024
I've been chewing on this for a bit, but it's pretty slow going since I'm also learning about a lot of compilation internals. As soon as I have something that is mostly compatible with the 3.12
typing.pyI will submit a partial PR to get some incremental feedback.youknowone commentedon Apr 22, 2024
That's awesome. Please feel free to ask anything if you stuck on something.
About typing module, if it helps, mixing Rust and Python implementation is limited but still possible. #5254 is doing it for ExceptionGroup.
hydrogen602 commentedon May 12, 2024
I don't know if this is already known, but I just wanted to add to the 3.12 typing discussion that if not running in release mode, syntax like
def foo[T](): passcauses a panic in the parser atcore/src/source_code.rs:139:9dchiquito commentedon May 13, 2024
That problem should be resolved as of #5319 / RustPython/Parser#120. Thanks for reporting!
hbina commentedon Jan 31, 2025
Hi, what is the progress on this? Is there a way I can help? Trying to get started with RustPython myself :)
youknowone commentedon Jan 31, 2025
@hbina Hi, open
Lib/test/test_typing.pyin RustPython source code and search# TODO: RUSTPYTHONin the file. You will find many failing tests from there. Removing one of them will makecargo run -- Lib/test/test_typing.pybe failed. That's the starting point.Please share any blocker you meet. Thanks!
arihant2math commentedon Mar 31, 2025
#5590 should fix this.