Skip to content

[mypyc] Fixing condition for handling user-defined __del__ #19188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2025

Conversation

advait-dixit
Copy link
Contributor

Fixes #19175.

Conditions for generating and invoking del method were not consistent. This change generates and invokes native code for dealloc and __del__ if either generate_full is True or class has a user-defined __del__ method.

@advait-dixit
Copy link
Contributor Author

@JukkaL @mr-c: Sorry, I had to re-work the PR because tests were failing for < 3.12.
As things currently stand, this pull request fixes the crash. However, for classes that derive from Python built-ins, user defined del will not be invoked. I had enhanced an existing test to check for no crashes and added a new test with "xfail" for non-compatability in user-defined del function. I can open a new issue for that as well.

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 quick fix! This is a reasonable short-term fix.

@JukkaL JukkaL changed the title [mypyc] Fixing condition for handling user-defined __del__. [mypyc] Fixing condition for handling user-defined __del__ Jun 2, 2025
@JukkaL JukkaL merged commit e50b401 into python:master Jun 2, 2025
13 checks passed
JukkaL pushed a commit that referenced this pull request Jun 11, 2025
Fixes #19175.

Conditions for generating and invoking `del` method were not consistent.

As things currently stand, this pull request fixes the crash. However, for classes that derive from Python built-ins, user-defined `__del__` will not be invoked.
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.

mypyc 1.16 regression: x86_64-cpython-3{9,10,11,12,13} error: ‘FOO_finalize’ undeclared here (not in a function); did you mean ‘FOO_init’?
2 participants