Debian Codegraph @

tests/data/cases/remove_with_brackets.py

raw
1 with (open("bla.txt")):
2 pass
3
4 with (open("bla.txt")), (open("bla.txt")):
5 pass
6
7 with (open("bla.txt") as f):
8 pass
9
10 # Remove brackets within alias expression
11 with (open("bla.txt")) as f:
12 pass
13
14 # Remove brackets around one-line context managers
15 with (open("bla.txt") as f, (open("x"))):
16 pass
17
18 with ((open("bla.txt")) as f, open("x")):
19 pass
20
21 with (CtxManager1() as example1, CtxManager2() as example2):
22 ...
23
24 # Brackets remain when using magic comma
25 with (CtxManager1() as example1, CtxManager2() as example2,):
26 ...
27
28 # Brackets remain for multi-line context managers
29 with (CtxManager1() as example1, CtxManager2() as example2, CtxManager2() as example2, CtxManager2() as example2, CtxManager2() as example2):
30 ...
31
32 # Don't touch assignment expressions
33 with (y := open("./test.py")) as f:
34 pass
35
36 # Deeply nested examples
37 # N.B. Multiple brackets are only possible
38 # around the context manager itself.
39 # Only one brackets is allowed around the
40 # alias expression or comma-delimited context managers.
41 with (((open("bla.txt")))):
42 pass
43
44 with (((open("bla.txt")))), (((open("bla.txt")))):
45 pass
46
47 with (((open("bla.txt")))) as f:
48 pass
49
50 with ((((open("bla.txt")))) as f):
51 pass
52
53 with ((((CtxManager1()))) as example1, (((CtxManager2()))) as example2):
54 ...
55
56 # regression tests for #3678
57 with (a, *b):
58 pass
59
60 with (a, (b, *c)):
61 pass
62
63 with (a for b in c):
64 pass
65
66 with (a, (b for c in d)):
67 pass
68
69 # output
70 with open("bla.txt"):
71 pass
72
73 with open("bla.txt"), open("bla.txt"):
74 pass
75
76 with open("bla.txt") as f:
77 pass
78
79 # Remove brackets within alias expression
80 with open("bla.txt") as f:
81 pass
82
83 # Remove brackets around one-line context managers
84 with open("bla.txt") as f, open("x"):
85 pass
86
87 with open("bla.txt") as f, open("x"):
88 pass
89
90 with CtxManager1() as example1, CtxManager2() as example2:
91 ...
92
93 # Brackets remain when using magic comma
94 with (
95 CtxManager1() as example1,
96 CtxManager2() as example2,
97 ):
98 ...
99
100 # Brackets remain for multi-line context managers
101 with (
102 CtxManager1() as example1,
103 CtxManager2() as example2,
104 CtxManager2() as example2,
105 CtxManager2() as example2,
106 CtxManager2() as example2,
107 ):
108 ...
109
110 # Don't touch assignment expressions
111 with (y := open("./test.py")) as f:
112 pass
113
114 # Deeply nested examples
115 # N.B. Multiple brackets are only possible
116 # around the context manager itself.
117 # Only one brackets is allowed around the
118 # alias expression or comma-delimited context managers.
119 with open("bla.txt"):
120 pass
121
122 with open("bla.txt"), open("bla.txt"):
123 pass
124
125 with open("bla.txt") as f:
126 pass
127
128 with open("bla.txt") as f:
129 pass
130
131 with CtxManager1() as example1, CtxManager2() as example2:
132 ...
133
134 # regression tests for #3678
135 with (a, *b):
136 pass
137
138 with a, (b, *c):
139 pass
140
141 with (a for b in c):
142 pass
143
144 with a, (b for c in d):
145 pass