Skip to content
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

Closed
roalddevries mannequin opened this issue Aug 6, 2010 · 5 comments
Closed

metaclass can't derive from ABC #53742

roalddevries mannequin opened this issue Aug 6, 2010 · 5 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@roalddevries
Copy link
Mannequin

roalddevries mannequin commented Aug 6, 2010

BPO 9533
Nosy @terryjreedy, @benjaminp, @merwok, @bitdancer, @durban
Files
  • bug.py: source file leading to the exception in the comment
  • 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:

    assignee = None
    closed_at = <Date 2010-10-02.17:53:46.500>
    created_at = <Date 2010-08-06.10:33:37.675>
    labels = ['type-bug', 'library']
    title = "metaclass can't derive from ABC"
    updated_at = <Date 2010-10-02.17:53:46.498>
    user = 'https://bugs.python.org/roalddevries'

    bugs.python.org fields:

    activity = <Date 2010-10-02.17:53:46.498>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-10-02.17:53:46.500>
    closer = 'benjamin.peterson'
    components = ['Library (Lib)']
    creation = <Date 2010-08-06.10:33:37.675>
    creator = 'roalddevries'
    dependencies = []
    files = ['18414']
    hgrepos = []
    issue_num = 9533
    keywords = []
    message_count = 5.0
    messages = ['113094', '114025', '117802', '117880', '117891']
    nosy_count = 6.0
    nosy_names = ['terry.reedy', 'benjamin.peterson', 'eric.araujo', 'r.david.murray', 'daniel.urban', 'roalddevries']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue9533'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @roalddevries
    Copy link
    Mannequin Author

    roalddevries mannequin commented Aug 6, 2010

    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

    @roalddevries roalddevries mannequin added the build The build process and cross-build label Aug 6, 2010
    @durban durban mannequin added type-bug An unexpected behavior, bug, or error and removed build The build process and cross-build labels Aug 6, 2010
    @terryjreedy
    Copy link
    Member

    +- same traceback in 3.1
    Since ABCmeta is not used (by name) its import is not needed.
    I have no opinion on whether this should work.

    @durban
    Copy link
    Mannequin

    durban mannequin commented Oct 1, 2010

    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:

    1. In ABCMeta.__new__ special case type (do not check its __abstractmethods__attribute).
    2. In ABCMeta.__new__ check if the __abstractmethods__ attribute is in fact an iterable, before we try to iterate over it. (I don't think this would be a very good solution, because if a base class' __abstractmethods__ isn't iterable, it should be an error, except if the base class is type itself. So we should special case type anyway.)

    I can't come up with a use case for this right now, but I don't see why it shouldn't work.

    @durban durban mannequin added the stdlib Python modules in the Lib dir label Oct 1, 2010
    @bitdancer
    Copy link
    Member

    Does the "fix" for bpo-10006 affect this? (I imagine that question is why Antoine made Benjamin nosy on this issue).

    @benjaminp
    Copy link
    Contributor

    You can now create metaclass abcs. However, having __abstractmethods__ does not prevent instance creation. This is a problem with a builtins, though.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants