Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypyc/codegen/emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ def emit_cpyfunction_instance(
) -> str:
module = self.static_name(fn.decl.module_name, None, prefix=MODULE_PREFIX)
cname = f"{PREFIX}{fn.cname(self.names)}"
wrapper_name = f"{cname}_wrapper"
wrapper_name = f"wrapper_{cname}"
cfunc = f"(PyCFunction){cname}"
func_flags = ["METH_FASTCALL", "METH_KEYWORDS"]
if fn.class_name and fn.decl.kind == FUNC_STATICMETHOD:
Expand Down
2 changes: 1 addition & 1 deletion mypyc/codegen/emitclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ def success() -> None:

name = short_id_from_name(fn.name, fn.decl.shortname, fn.line)
wrapper_name = emit_instance(fn, name)
name_obj = f"{wrapper_name}_name"
name_obj = f"name_{wrapper_name}"
emitter.emit_line(f'PyObject *{name_obj} = PyUnicode_FromString("{fn.name}");')
emitter.emit_line(f"if (unlikely(!{name_obj}))")
emitter.emit_line(error_stmt)
Expand Down
2 changes: 1 addition & 1 deletion mypyc/codegen/emitmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ def emit_coroutine_wrappers(self, emitter: Emitter, module: ModuleIR, globals: s
error_stmt = " goto fail;"
name = short_id_from_name(fn.name, fn.decl.shortname, fn.line)
wrapper_name = emitter.emit_cpyfunction_instance(fn, name, filepath, error_stmt)
name_obj = f"{wrapper_name}_name"
name_obj = f"name_{wrapper_name}"
emitter.emit_line(f'PyObject *{name_obj} = PyUnicode_FromString("{fn.name}");')
emitter.emit_line(f"if (unlikely(!{name_obj}))")
emitter.emit_line(error_stmt)
Expand Down
41 changes: 41 additions & 0 deletions mypyc/test-data/run-async.test
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,47 @@ from typing import Any, Generator

def run(x: object) -> object: ...

[case testCPyFunctionVariableNameConflict]
class C:
async def operation(self) -> int:
return 42

async def operation_name(self) -> str:
return "name"

async def name_operation(self) -> str:
return await self.operation_name()

async def operation_wrapper(self) -> int:
return await self.operation()

async def wrapper_operation(self) -> int:
return await self.operation()

async def test_variable_name_conflict() -> None:
c = C()
assert await c.operation() == 42
assert await c.operation_wrapper() == 42
assert await c.wrapper_operation() == 42
assert await c.operation_name() == "name"
assert await c.name_operation() == "name"

[file driver.py]
import asyncio

from native import C, test_variable_name_conflict

async def test_variable_name_conflict_interpreted() -> None:
c = C()
assert await c.operation() == 42
assert await c.operation_wrapper() == 42
assert await c.wrapper_operation() == 42
assert await c.operation_name() == "name"
assert await c.name_operation() == "name"

asyncio.run(test_variable_name_conflict())
asyncio.run(test_variable_name_conflict_interpreted())

[case testNestedCoroutineCallsAnotherNestedFunction]
import asyncio
import functools
Expand Down
Loading