Skip to content

replace @overload # force merge with something else #788

Open
@Josverl

Description

@Josverl

To replace @overload

from typing import List, Optional, Tuple, Union, Callable
import functools
from typing_extensions import reveal_type

from typing_extensions import ParamSpec, TypeVar

P = ParamSpec("P")
R = TypeVar("R")


def mpy_port(
             _func: Optional[Callable[P, R]] = None,
             /, 
             port: Union[str, List[str]] = "*",
             feature: Union[str, List[str]] = "*",
            ) -> Callable[P, R]: 
    """Decorator to mark a function as supported only for a specific MicroPython port."""
    ...


@mpy_port(port="*")
def a(str, i: int = 1) -> Tuple[str, float]:
    ...

@mpy_port(feature="*")
def B(str, i: int = 1) -> Tuple[str, float]:
    ...

@mpy_port(port=["esp32", "esp8266"])
def espnow(str, i: int = 1) -> Tuple[str, float]:
    print("foo")
    return str * i, float(i)


reveal_type(espnow("booh", 32))

merge/enrich functions can evalute the params to determine if a class / method should be made available to a port

will anso need either :

  • runtime support ( ... )
  • a way to remove these annotations from the stubs before publication
    • using a comment
    • by a cleanup codemod

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions