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

Abstract classes derived from built-in classes don't block instance creation #75310

Closed
KevinShweh mannequin opened this issue Aug 6, 2017 · 2 comments
Closed

Abstract classes derived from built-in classes don't block instance creation #75310

KevinShweh mannequin opened this issue Aug 6, 2017 · 2 comments
Labels
docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@KevinShweh
Copy link
Mannequin

KevinShweh mannequin commented Aug 6, 2017

BPO 31127
Nosy @bitdancer
Superseder
  • bpo-5996: abstract class instantiable when subclassing built-in types
  • 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 2017-08-06.21:39:14.711>
    created_at = <Date 2017-08-06.19:00:42.367>
    labels = ['type-bug', 'library', 'docs']
    title = "Abstract classes derived from built-in classes don't block instance creation"
    updated_at = <Date 2017-08-06.21:39:14.709>
    user = 'https://bugs.python.org/KevinShweh'

    bugs.python.org fields:

    activity = <Date 2017-08-06.21:39:14.709>
    actor = 'r.david.murray'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2017-08-06.21:39:14.711>
    closer = 'r.david.murray'
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2017-08-06.19:00:42.367>
    creator = 'Kevin Shweh'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31127
    keywords = []
    message_count = 2.0
    messages = ['299810', '299814']
    nosy_count = 3.0
    nosy_names = ['r.david.murray', 'docs@python', 'Kevin Shweh']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '5996'
    type = 'behavior'
    url = 'https://bugs.python.org/issue31127'
    versions = ['Python 2.7', 'Python 3.6']

    @KevinShweh
    Copy link
    Mannequin Author

    KevinShweh mannequin commented Aug 6, 2017

    The only check that prevents instantiating abstract classes is in object.__new__, but most built-in classes never actually call object.__new__. That means you can do stuff like

    import abc
    
    class Foo(list, metaclass=abc.ABCMeta):
    	@abc.abstractmethod
    	def abstract(self):
    		pass
    
    Foo()

    and the Foo() call will silently succeed.

    Ideally, the Foo() call should fail. Other options include having the Foo class definition itself fail, or just making a note in the documentation describing the limitation. (As far as I can see, this is currently undocumented.)

    @KevinShweh KevinShweh mannequin assigned docspython Aug 6, 2017
    @KevinShweh KevinShweh mannequin added docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 6, 2017
    @bitdancer
    Copy link
    Member

    This is a duplidate of bpo-5996. It is not clear if we are going to treat it as a bug or a doc bug.

    @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
    docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant