basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

new based syntax

Open KotlinIsland opened this issue 1 year ago • 1 comments

stringizer will kill us, but anyway:

cpython compatible based syntax:

  • (str) > int for callable syntax, annoyingly ast wont see the parens here
  • "foo" | "bar" for string literals, will need to be a per module setting (also need a fallback option for forward refs #361)
  • f"a_{int}" for template literals or w/e we call them

custom only based syntax:

  • def f[T: Overload[str, int]](): for constrained types T: (str, int) is stupid
  • (int=, /, *, foo: str=, **bar: str) -> int fullform callable syntax (= or =... for default?)

KotlinIsland avatar Aug 19 '24 00:08 KotlinIsland

wish moment, how should tuple/dict/*args/**kwargs work:

tuple/*args

def f1(*args: tuple[int]): ...
f1(1, 2, 3)

def f2(*args: *int): ...
f2(1, 2, 3)

def f3(*args: (int, str)):
f3(1, "a")

v1: tuple[int] = 1, 2, 3
v2: *int = 1, 2, 3
v3: (int, str) = 1, "a" 

edge case:

yeah: tuple[()] = (), (), ()

dict/**kwargs

would be similar and consistent:

def f1(**kwargs: dict[str, int]): ...
f1(a=1, b=2, c=3)

def f2(**kwargs: **int): ...
f2(a=1, b=2, c=3)

def f3(**kwargs: {"a": int}):
f3(a=1)

v1: dict[str, int] = {"a": 1, "b": 2, "c": 3}
v2: **int = {"a": 1, "b": 2, "c": 3}
v3: {"a": str} = {"a": 1}

edge case:

yeah: dict[str, {}] = {"a": {}, "b": {}, "c": {}}

KotlinIsland avatar Aug 31 '24 05:08 KotlinIsland