File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -1246,14 +1246,15 @@ def add_var_to_env_class(
12461246 ) -> AssignmentTarget :
12471247 # First, define the variable name as an attribute of the environment class, and then
12481248 # construct a target for that attribute.
1249- self .fn_info .env_class .attributes [var .name ] = rtype
1250- attr_target = AssignmentTargetAttr (base .curr_env_reg , var .name )
1249+ name = remangle_redefinition_name (var .name )
1250+ self .fn_info .env_class .attributes [name ] = rtype
1251+ attr_target = AssignmentTargetAttr (base .curr_env_reg , name )
12511252
12521253 if reassign :
12531254 # Read the local definition of the variable, and set the corresponding attribute of
12541255 # the environment class' variable to be that value.
12551256 reg = self .read (self .lookup (var ), self .fn_info .fitem .line )
1256- self .add (SetAttr (base .curr_env_reg , var . name , reg , self .fn_info .fitem .line ))
1257+ self .add (SetAttr (base .curr_env_reg , name , reg , self .fn_info .fitem .line ))
12571258
12581259 # Override the local definition of the variable to instead point at the variable in
12591260 # the environment class.
Original file line number Diff line number Diff line change @@ -143,3 +143,31 @@ async def foo() -> AsyncIterable[int]:
143143yields, val = run_generator(async_iter(foo()))
144144assert yields == (0,1,2), yields
145145assert val == 'lol no', val
146+
147+ [case testAsyncWithVarReuse]
148+ class ConMan:
149+ async def __aenter__(self) -> int:
150+ return 1
151+ async def __aexit__(self, *exc: object):
152+ pass
153+
154+ class ConManB:
155+ async def __aenter__(self) -> int:
156+ return 2
157+ async def __aexit__(self, *exc: object):
158+ pass
159+
160+ async def x() -> None:
161+ value = 2
162+ async with ConMan() as f:
163+ value += f
164+ assert value == 3, value
165+ async with ConManB() as f:
166+ value += f
167+ assert value == 5, value
168+
169+ [typing fixtures/typing-full.pyi]
170+ [file driver.py]
171+ import asyncio
172+ import native
173+ asyncio.run(native.x())
You can’t perform that action at this time.
0 commit comments