classification
Title: Abstract classes derived from built-in classes don't block instance creation
Type: behavior Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.6, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: abstract class instantiable when subclassing built-in types
View: 5996
Assigned To: docs@python Nosy List: Kevin Shweh, docs@python, r.david.murray
Priority: normal Keywords:

Created on 2017-08-06 19:00 by Kevin Shweh, last changed 2017-08-06 21:39 by r.david.murray. This issue is now closed.

Messages (2)
msg299810 - (view) Author: Kevin Shweh (Kevin Shweh) Date: 2017-08-06 19:00
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.)
msg299814 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-08-06 21:39
This is a duplidate of issue 5996.  It is not clear if we are going to treat it as a bug or a doc bug.
History
Date User Action Args
2017-08-06 21:39:14r.david.murraysetstatus: open -> closed

superseder: abstract class instantiable when subclassing built-in types

nosy: + r.david.murray
messages: + msg299814
resolution: duplicate
stage: resolved
2017-08-06 19:00:42Kevin Shwehcreate