You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A class with __abstractmethods__ can be instantiated once its call is specialized to CALL_ALLOC_AND_ENTER_INIT #162600
For a plain class with a Python __init__ and a non-empty __abstractmethods__, the first evaluation of A() raises TypeError: Can't instantiate abstract class, and the later ones of the same call return instances:
On 3.12 every call raises. specialize_class_call (Python/specialize.c) picks CALL_ALLOC_AND_ENTER_INIT, which skips object_new and so its check of Py_TPFLAGS_IS_ABSTRACT; checking the flag there would keep the error. It needs __abstractmethods__ set by hand (classes with ABCMeta are not specialized this way), but the result of the same expression shouldn't change after a few calls. I found it while writing a Lean spec of Python.
Thank you for taking the time to open this issue. Python is a community-driven project, and we want it to be a welcoming place to learn and collaborate.
This issue appears to have been written with AI assistance. Please explain your issue in your own words and describe how you checked the information you provided. This helps us understand your issue and leaves more time to address other issues.
It needs __abstractmethods__ set by hand (classes with ABCMeta are not specialized this way), but the result of the same expression shouldn't change after a few calls.
I believe this is where we disagree. I don't think this is meant to be the case. Users are not meant to write this by hand unless they know what they are doing and thus I believe it's something that doesn't qualify as a real bug.
OTOH, if the fix does not reduce performance, we can accept it. However we definitely don't want to slow down others just because of singular cases. How much performance change are we having if we were to to fix this? (on a PGO+LTO build with say pydantic models and dataclasses, as well as regular simple classes).
That's fair, it does need __abstractmethods__ set by hand. On the cost: the check would go in specialize_class_call, which runs when a call site specializes, so CALL_ALLOC_AND_ENTER_INIT itself doesn't change. Setting __abstractmethods__ later invalidates the type's version tag, which the instruction already guards on. I haven't benchmarked it. Happy to send a PR, or to close this if you'd still rather leave it.
Activity
bedevere-app commentedon Nov 25, 2026
Thank you for taking the time to open this issue. Python is a community-driven project, and we want it to be a welcoming place to learn and collaborate.
This issue appears to have been written with AI assistance. Please explain your issue in your own words and describe how you checked the information you provided. This helps us understand your issue and leaves more time to address other issues.
Please read our guidelines for using AI tools.
picnixz commentedon Nov 25, 2026
I believe this is where we disagree. I don't think this is meant to be the case. Users are not meant to write this by hand unless they know what they are doing and thus I believe it's something that doesn't qualify as a real bug.
OTOH, if the fix does not reduce performance, we can accept it. However we definitely don't want to slow down others just because of singular cases. How much performance change are we having if we were to to fix this? (on a PGO+LTO build with say pydantic models and dataclasses, as well as regular simple classes).
Robertboy18 commentedon Nov 27, 2026
That's fair, it does need
__abstractmethods__set by hand. On the cost: the check would go inspecialize_class_call, which runs when a call site specializes, soCALL_ALLOC_AND_ENTER_INITitself doesn't change. Setting__abstractmethods__later invalidates the type's version tag, which the instruction already guards on. I haven't benchmarked it. Happy to send a PR, or to close this if you'd still rather leave it.picnixz commentedon Nov 27, 2026
I think we can fix this though since it's still a bug but we should be careful with performance just in case. cc @eendebakpt