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
metaclass can't derive from ABC #53742
Comments
Exception raised:: Traceback (most recent call last):
File "bug.py", line 5, in <module>
class derived(type, Sized):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/abc.py", line 85, in __new__
for name in getattr(base, "__abstractmethods__", set()):
TypeError: Error when calling the metaclass bases
'getset_descriptor' object is not iterable |
+- same traceback in 3.1 |
If we create a new class, which is a metaclass, and also inherits an ABC, we create a new instance of ABCMeta. When ABCMeta.__new__ creates the __abstractmethods__ attribute of the new class, it iterates over the __abstractmethods__ attribute of every base class (and checks every name in it, if it's abstract in the new class). One of the base classes of a metaclass is of course type. The type.__abstractmethods__ object is a getset descriptor (its __set__ switches some flags in tp_flags), which isn't iterable, so it raises the exception. Ideas for possible solutions:
I can't come up with a use case for this right now, but I don't see why it shouldn't work. |
Does the "fix" for bpo-10006 affect this? (I imagine that question is why Antoine made Benjamin nosy on this issue). |
You can now create metaclass abcs. However, having __abstractmethods__ does not prevent instance creation. This is a problem with a builtins, though. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: