Skip to content

machine/micropython/time/utime can't match MicroPython's positional-only C-function signatures: the compiler has no PEP 3102 / syntax #12

Description

@begeistert

What happens

MicroPython's own .pyi stubs (micropython-rp2-stubs, the parity suite's reference) mark
every C-implemented function and most method setters as positional-only, using PEP 3102's
/ marker: def sleep(seconds, /) -> None: .... This layer's real Python source can never
match that shape, because neither PyMCU frontend parses /:

  • The hand-written C# parser (src/compiler/Frontend/Parser.cs, ParseParameters()) has no
    branch for TokenType.Slash; def f(a, /, b=0): is a hard parse error there today
    ("Expected parameter name", pointing at the /).
  • The CPython-ast frontend (PYMCU_PY_PARSER=1, Frontend/PyParser/pymcu_translate.py)
    parses / without erroring, but silently merges posonlyargs into the ordinary
    positional list (no flag is ever emitted), so the restriction is a no-op even there.
  • Param (src/compiler/Frontend/Ast.cs) has no positional-only flag at all, and call
    binding (src/compiler/IR/IRGenerator/Call.cs) matches keywords purely by name.

Since the default frontend is the C# parser, / cannot be used in this repo's source without
breaking the build for anyone not setting PYMCU_PY_PARSER=1.

What this blocks

tests/parity/ compares this layer's real (CPython-importable) function signatures against
the stub via inspect.signature, which correctly reports POSITIONAL_ONLY for stub params
before /. Every one of the symbols below differs from its stub only in that kind (name,
default and required-ness already agree, or agree once the harmless renames below are made);
none of them can be closed until the compiler accepts /.

Fix

Add / support to src/compiler/Frontend/Parser.cs (ParseParameters(), mirroring the
existing bare-* handling), a positional-only flag on Param, and the matching change in
pymcu_translate.py/PythonAstReader.cs so both frontends agree. This is a compiler-repo
change (PyMCU/PyMCU); tracked here because it blocks this layer's own parity suite
(tests/parity/, allowlisted tracked:#<this issue>).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions