Type alias stub for formatter (#5880)

**Summary** This replaces the `todo!()` with a type alias stub in the
formatter. I added the tests from
704eb40108/parser/src/parser.rs (L901-L936)
as ruff python formatter tests.

**Test Plan** None, testing is part of the actual implementation
This commit is contained in:
konsti 2023-07-19 17:28:07 +02:00 committed by GitHub
parent a51606a10a
commit a227775f62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 748 additions and 1 deletions

View file

@ -0,0 +1,5 @@
type A=int
type Gen[T]=list[T]
type = aliased
print(type(42))

View file

@ -0,0 +1,5 @@
type A = int
type Gen[T] = list[T]
type = aliased
print(type(42))

View file

@ -0,0 +1,13 @@
def func [T ](): pass
async def func [ T ] (): pass
class C[ T ] : pass
def all_in[T : int,U : (bytes, str),* Ts,**P](): pass
def really_long[WhatIsTheLongestTypeVarNameYouCanThinkOfEnoughToMakeBlackSplitThisLine](): pass
def even_longer[WhatIsTheLongestTypeVarNameYouCanThinkOfEnoughToMakeBlackSplitThisLine: WhatIfItHadABound](): pass
def it_gets_worse[WhatIsTheLongestTypeVarNameYouCanThinkOfEnoughToMakeBlackSplitThisLine, ItCouldBeGenericOverMultipleTypeVars](): pass
def magic[Trailing, Comma,](): pass

View file

@ -0,0 +1,40 @@
def func[T]():
pass
async def func[T]():
pass
class C[T]:
pass
def all_in[T: int, U: (bytes, str), *Ts, **P]():
pass
def really_long[
WhatIsTheLongestTypeVarNameYouCanThinkOfEnoughToMakeBlackSplitThisLine
]():
pass
def even_longer[
WhatIsTheLongestTypeVarNameYouCanThinkOfEnoughToMakeBlackSplitThisLine: WhatIfItHadABound
]():
pass
def it_gets_worse[
WhatIsTheLongestTypeVarNameYouCanThinkOfEnoughToMakeBlackSplitThisLine,
ItCouldBeGenericOverMultipleTypeVars,
]():
pass
def magic[
Trailing,
Comma,
]():
pass

View file

@ -154,6 +154,9 @@ class Test:
not parsed.hostname.strip()):
pass
a = "type comment with trailing space" # type: str
#######################
### SECTION COMMENT ###
#######################

View file

@ -162,6 +162,8 @@ class Test:
pass
a = "type comment with trailing space" # type: str
#######################
### SECTION COMMENT ###
#######################

View file

@ -0,0 +1,20 @@
def f(): # type: ignore
...
class x: # some comment
...
class y:
... # comment
# whitespace doesn't matter (note the next line has a trailing space and tab)
class z:
...
def g():
# hi
...
def h():
...
# bye

View file

@ -0,0 +1,18 @@
def f(): # type: ignore
...
class x: # some comment
...
class y: ... # comment
# whitespace doesn't matter (note the next line has a trailing space and tab)
class z: ...
def g():
# hi
...
def h():
...
# bye

View file

@ -0,0 +1,21 @@
# This is a regression test. Issue #3737
a = ( # type: ignore
int( # type: ignore
int( # type: ignore
int( # type: ignore
6
)
)
)
)
b = (
int(
6
)
)
print( "111") # type: ignore
print( "111" ) # type: ignore
print( "111" ) # type: ignore

View file

@ -0,0 +1,15 @@
# This is a regression test. Issue #3737
a = ( # type: ignore
int( # type: ignore
int( # type: ignore
int(6) # type: ignore
)
)
)
b = int(6)
print("111") # type: ignore
print("111") # type: ignore
print("111") # type: ignore

View file

@ -49,6 +49,7 @@ FIXTURE_SETS = [
"py_39",
"py_310",
"py_311",
"py_312",
"simple_cases",
"miscellaneous",
".",

View file

@ -0,0 +1,38 @@
# Copied from https://github.com/RustPython/Parser/blob/704eb40108239a8faf9bd1d4217e8dad0ac7edb3/parser/src/parser.rs#L901-L936
type X = int
type X = int | str
type X = int | "ForwardRefY"
type X[T] = T | list[X[T]] # recursive
type X[T] = int
type X[T] = list[T] | set[T]
type X[T, *Ts, **P] = (T, Ts, P)
type X[T: int, *Ts, **P] = (T, Ts, P)
type X[T: (int, str), *Ts, **P] = (T, Ts, P)
# soft keyword as alias name
type type = int
type match = int
type case = int
# soft keyword as value
type foo = type
type foo = match
type foo = case
# multine definitions
type \
X = int
type X \
= int
type X = \
int
type X = (
int
)
type \
X[T] = T
type X \
[T] = T
type X[T] \
= T