Skip to content

Commit 8a21e88

Browse files
authored
test: add test to show walrus operator is supported (#80)
1 parent 674baa5 commit 8a21e88

File tree

5 files changed

+153
-1
lines changed

5 files changed

+153
-1
lines changed

.github/workflows/scip-docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
- 'Dockerfile.autoindex'
1111

1212
jobs:
13-
release-image:
13+
build-image:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v3
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import re
2+
3+
some_list = [1, 2, 3, 4, 5, 100, 1000]
4+
pattern = "^[A-Za-z0-9_]*$"
5+
text = "Some_name123"
6+
7+
# if statement
8+
if (n := len(some_list)) > 10:
9+
print(f"List is too long with {n} elements.")
10+
11+
if (match := re.search(pattern, text)) is not None:
12+
print("Found match:", match.group(0))
13+
14+
15+
# comprehensions
16+
def show_some_comprehension():
17+
[print(x, root) for x in some_list if (x % 2 == 0) and (root := x**0.5) > 5]
18+
19+
20+
# while loop
21+
while (line := input("Enter text: ")) != "quit":
22+
print(f"You entered: {line}")
23+
24+
25+
# if + comprehension
26+
if any((any_n := num) < 0 for num in some_list):
27+
print(f"Negative number found: {any_n}")

packages/pyright-scip/snapshots/output/unique/property_access.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def nested():
8484
# > ```
8585
for x in xs:
8686
# ^ definition local 0
87+
# external documentation ```python
88+
# > (function) def len(
89+
# > __obj: Sized,
90+
# > /
91+
# > ) -> int
92+
# > ```
8793
# ^^ reference snapshot-util 0.1 property_access/usage().(xs)
8894
print(x.prop_ref)
8995
# ^^^^^ reference python-stdlib 3.11 builtins/print().

packages/pyright-scip/snapshots/output/unique/vars_inside_scopes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ def my_func(self):
5757
# ^^^^ definition snapshot-util 0.1 vars_inside_scopes/X#my_func().(self)
5858
for x in self.items:
5959
# ^ definition local 0
60+
# external documentation ```python
61+
# > (function) def len(
62+
# > __obj: Sized,
63+
# > /
64+
# > ) -> int
65+
# > ```
6066
# ^^^^ reference snapshot-util 0.1 vars_inside_scopes/X#my_func().(self)
6167
# ^^^^^ reference snapshot-util 0.1 vars_inside_scopes/X#items.
6268
y = x + 1
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# < definition scip-python python snapshot-util 0.1 walrus/__init__:
2+
#documentation (module) walrus
3+
4+
import re
5+
# ^^ reference python-stdlib 3.11 re/__init__:
6+
7+
some_list = [1, 2, 3, 4, 5, 100, 1000]
8+
#^^^^^^^^ definition snapshot-util 0.1 walrus/some_list.
9+
#documentation ```python
10+
# > builtins.list
11+
# > ```
12+
pattern = "^[A-Za-z0-9_]*$"
13+
#^^^^^^ definition snapshot-util 0.1 walrus/pattern.
14+
#documentation ```python
15+
# > builtins.str
16+
# > ```
17+
text = "Some_name123"
18+
#^^^ definition snapshot-util 0.1 walrus/text.
19+
#documentation ```python
20+
# > builtins.str
21+
# > ```
22+
23+
# if statement
24+
if (n := len(some_list)) > 10:
25+
# ^ definition snapshot-util 0.1 walrus/n.
26+
# ^^^ reference local 0
27+
# external documentation ```python
28+
# > (function) def len(
29+
# > __obj: Sized,
30+
# > /
31+
# > ) -> int
32+
# > ```
33+
# ^^^^^^^^^ reference snapshot-util 0.1 walrus/some_list.
34+
print(f"List is too long with {n} elements.")
35+
# ^^^^^ reference python-stdlib 3.11 builtins/print().
36+
# external documentation ```python
37+
# > (function) def print(
38+
# > *values: object,
39+
# > sep: str | None = " ",
40+
# > end: str | None = "\n",
41+
# > file: SupportsWrite[str] | None = No...
42+
# > flush: Literal[False] = False
43+
# > ) -> None
44+
# > ```
45+
# ^ reference snapshot-util 0.1 walrus/n.
46+
47+
if (match := re.search(pattern, text)) is not None:
48+
# ^^^^^ definition snapshot-util 0.1 walrus/match.
49+
# ^^ reference python-stdlib 3.11 re/__init__:
50+
# ^^^^^^ reference python-stdlib 3.11 re/search().
51+
# ^^^^^^^ reference snapshot-util 0.1 walrus/pattern.
52+
# ^^^^ reference snapshot-util 0.1 walrus/text.
53+
print("Found match:", match.group(0))
54+
# ^^^^^ reference python-stdlib 3.11 builtins/print().
55+
# ^^^^^ reference snapshot-util 0.1 walrus/match.
56+
# ^^^^^ reference python-stdlib 3.11 re/Match#group().
57+
58+
59+
# comprehensions
60+
def show_some_comprehension():
61+
# ^^^^^^^^^^^^^^^^^^^^^^^ definition snapshot-util 0.1 walrus/show_some_comprehension().
62+
# documentation ```python
63+
# > def show_some_comprehension(): # -> None...
64+
# > ```
65+
[print(x, root) for x in some_list if (x % 2 == 0) and (root := x**0.5) > 5]
66+
# ^^^^^ reference python-stdlib 3.11 builtins/print().
67+
# ^ reference local 1
68+
# ^^^^ reference local 2
69+
# ^ definition local 1
70+
# documentation ```python
71+
# > (variable) x: int
72+
# > ```
73+
# ^^^^^^^^^ reference snapshot-util 0.1 walrus/some_list.
74+
# ^ reference local 1
75+
# ^^^^ definition local 2
76+
# ^ reference local 1
77+
78+
79+
# while loop
80+
while (line := input("Enter text: ")) != "quit":
81+
# ^^^^ definition snapshot-util 0.1 walrus/line.
82+
# ^^^^^ reference local 3
83+
# external documentation ```python
84+
# > (function) def input(
85+
# > __prompt: object = "",
86+
# > /
87+
# > ) -> str
88+
# > ```
89+
print(f"You entered: {line}")
90+
# ^^^^^ reference python-stdlib 3.11 builtins/print().
91+
# ^^^^ reference snapshot-util 0.1 walrus/line.
92+
93+
94+
# if + comprehension
95+
if any((any_n := num) < 0 for num in some_list):
96+
# ^^^ reference local 4
97+
# external documentation ```python
98+
# > (function) def any(
99+
# > __iterable: Iterable[object],
100+
# > /
101+
# > ) -> bool
102+
# > ```
103+
# ^^^^^ definition any_n.
104+
# ^^^ reference local 5
105+
# ^^^ definition local 5
106+
# documentation ```python
107+
# > (variable) num: int
108+
# > ```
109+
# ^^^^^^^^^ reference snapshot-util 0.1 walrus/some_list.
110+
print(f"Negative number found: {any_n}")
111+
# ^^^^^ reference python-stdlib 3.11 builtins/print().
112+
# ^^^^^ reference any_n.
113+

0 commit comments

Comments
 (0)