Skip to content

Conversation

@p-sawicki
Copy link
Collaborator

@p-sawicki p-sawicki commented Jan 28, 2026

This happens when a nested function has different definitions in different condition branches. mypyc currently crashes in this case when calling get_func_target in transform_decorator https://github.com/python/mypy/blob/master/mypyc/irbuild/function.py#L118.

The FuncDef objects for the definitions after the first one will have the original_def attribute set. This makes get_func_target lookup this original def but it doesn't find it when the original def is a decorator because registers are only created for FuncDefs.

Extracting a FuncDef from the original decorator and looking it up instead fixes the crash.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, one suggestion about another case to test.

async def wrapper(*args, **kwargs) -> Any:
return get_multiplier() * await fn(*args, **kwargs)
else:
@functools.wraps(fn)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also test this without using @functools_wraps? It might behave differently.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, turns out the fix wasn't right for all cases so i have updated it and added another test.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more test case ideas, since this area seems to be have bugs: can you also test cases where none of the conditional variants are decorated, or some of variants are decorated (all of these could include sync + a mix of async/sync functions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants