Skip to content

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

Description

@KevinShweh
mannequin
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']

    Activity

    1. KevinShweh commented on Aug 6, 2017

      KevinShwehmannequin
      MannequinAuthor

      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.)

    2. added
      docsDocumentation in the Doc dir
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Aug 6, 2017
    3. bitdancer commented on Aug 6, 2017

      @bitdancer
      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.

    4. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      docsDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions