-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed
Labels
3.13bugs and security fixesbugs and security fixestopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Good day to you, dear Python maintainers! I have a little issue with the recent Python release, 3.13. Here's a snippet:
import ctypes
class EnumMetaclass(type(ctypes.c_uint)):
def __new__(metaclass, name, bases, cls_dict):
cls = type(ctypes.c_uint).__new__(metaclass, name, bases, cls_dict)
if name == 'Enum':
return cls
for i, value in enumerate(cls_dict['_values_']):
setattr(cls, value, cls.from_param(i))
return cls
class Enum(ctypes.c_uint, metaclass=EnumMetaclass):
@classmethod
def from_param(cls, param):
print("Calling method 'from_param' of", cls)
return cls(param)
def __repr__(self):
return self._values_[self.value]
class NodeType(Enum):
_values_ = ['DOCUMENT', 'ELEMENT', 'TEXT']
def main():
print(NodeType(1))
if __name__ == "__main__":
main()
When run with Python 3.12.7
, I get the following output:
Calling method 'from_param' of <class '__main__.NodeType'>
Calling method 'from_param' of <class '__main__.NodeType'>
Calling method 'from_param' of <class '__main__.NodeType'>
ELEMENT
When run with Python 3.13.1
, I get the following output:
Calling method 'from_param' of <class '__main__.NodeType'>
Traceback (most recent call last):
File "/home/grisha/test.py", line 20, in <module>
class NodeType(Enum):
_values_ = ['DOCUMENT', 'ELEMENT', 'TEXT']
File "/home/grisha/test.py", line 9, in __new__
setattr(cls, value, cls.from_param(i))
~~~~~~~~~~~~~~^^^
File "/home/grisha/test.py", line 16, in from_param
return cls(param)
TypeError: abstract class
As you can see, new TypeError detection triggers where it presumably mustn't have, because it's perfectly correct to call from_param
from NodeType
object.
I checked that this problem persists in both 3.13.0
and 3.13.1
.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixestopic-ctypestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error