Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update typing to 3.12 #5252

Closed
Closed
@dchiquito

Description

@dchiquito

Feature

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 syntax like type type aliases and generics to the parser. It seems like this is already included in https://github.com/RustPython/Parser/blob/main/parser/src/python.lalrpop
  • 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

https://docs.python.org/3/library/typing.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-compatA discrepancy between RustPython and CPython

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions