Skip to content

replace @overload # force merge with something else #788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Josverl opened this issue Feb 6, 2025 · 0 comments
Open

replace @overload # force merge with something else #788

Josverl opened this issue Feb 6, 2025 · 0 comments
Assignees

Comments

@Josverl
Copy link
Owner

Josverl commented Feb 6, 2025

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
@Josverl Josverl self-assigned this Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant