Skip to content

Commit 3a0207b

Browse files
authored
Add test for new walrus semantics allowed in Python 3.12 (#21351)
1 parent 7caa629 commit 3a0207b

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

test-data/unit/check-python312.test

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,44 @@ type YNested = (1 + (yield from [])) # E: Yield expression cannot be used within
18181818
type ZNested = (1 + (a := 1)) # E: Named expression cannot be used within a type alias
18191819
type KNested = (1 + (await 1)) # E: Await expression cannot be used within a type alias
18201820

1821+
[case testWalrusRebindsNamesLoadedInComprehensionTargets]
1822+
# Newly legal in https://github.com/python/cpython/pull/100581
1823+
from typing import Any
1824+
1825+
def f(c: Any, d: Any, e: Any, f: Any, g: Any, h: Any, j: Any) -> None:
1826+
((c := 1) for a, (*b, c[d+e::f(g)], h.i) in j)
1827+
[(c := 1) for a, (*b, c[d+e::f(g)], h.i) in j]
1828+
{(c := 1) for a, (*b, c[d+e::f(g)], h.i) in j}
1829+
1830+
((d := 1) for a, (*b, c[d+e::f(g)], h.i) in j)
1831+
[(d := 1) for a, (*b, c[d+e::f(g)], h.i) in j]
1832+
{(d := 1) for a, (*b, c[d+e::f(g)], h.i) in j}
1833+
1834+
((e := 1) for a, (*b, c[d+e::f(g)], h.i) in j)
1835+
[(e := 1) for a, (*b, c[d+e::f(g)], h.i) in j]
1836+
{(e := 1) for a, (*b, c[d+e::f(g)], h.i) in j}
1837+
1838+
((f := 1) for a, (*b, c[d+e::f(g)], h.i) in j)
1839+
[(f := 1) for a, (*b, c[d+e::f(g)], h.i) in j]
1840+
{(f := 1) for a, (*b, c[d+e::f(g)], h.i) in j}
1841+
1842+
((g := 1) for a, (*b, c[d+e::f(g)], h.i) in j)
1843+
[(g := 1) for a, (*b, c[d+e::f(g)], h.i) in j]
1844+
{(g := 1) for a, (*b, c[d+e::f(g)], h.i) in j}
1845+
1846+
((h := 1) for a, (*b, c[d+e::f(g)], h.i) in j)
1847+
[(h := 1) for a, (*b, c[d+e::f(g)], h.i) in j]
1848+
{(h := 1) for a, (*b, c[d+e::f(g)], h.i) in j}
1849+
1850+
((i := 1) for a, (*b, c[d+e::f(g)], h.i) in j)
1851+
[(i := 1) for a, (*b, c[d+e::f(g)], h.i) in j]
1852+
{(i := 1) for a, (*b, c[d+e::f(g)], h.i) in j}
1853+
1854+
((j := 1) for a, (*b, c[d+e::f(g)], h.i) in j)
1855+
[(j := 1) for a, (*b, c[d+e::f(g)], h.i) in j]
1856+
{(j := 1) for a, (*b, c[d+e::f(g)], h.i) in j}
1857+
[builtins fixtures/primitives.pyi]
1858+
18211859
[case testPEP695TypeAliasAndAnnotated]
18221860
from typing_extensions import Annotated, Annotated as _Annotated
18231861
import typing_extensions as t

test-data/unit/fixtures/primitives.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,5 @@ class range(Sequence[int]):
8181
def isinstance(x: object, t: Union[type, Tuple]) -> bool: pass
8282

8383
class BaseException: pass
84+
85+
class slice: pass

0 commit comments

Comments
 (0)