This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Errors registering non-classes with ABCs
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: acooke, benjamin.peterson, cjw296
Priority: normal Keywords:

Created on 2010-01-26 22:53 by acooke, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg98387 - (view) Author: andrew cooke (acooke) Date: 2010-01-26 22:53
There are two related issues here.  The first is, I think, a simple bug:

When I try to register a function as a subclass of an ABC I get the error:
  TypeError: issubclass() arg 2 must be a class or tuple of classes

Looking at the code - http://svn.python.org/view/python/trunk/Lib/abc.py?annotate=72278 - it seems that instead the test at line 99 should have triggered a better error: TypeError("Can only register classes") 

In other words, line 99 should read:
  if not isinstance(subclass, type): 
(currently the code tests the "self class", cls, which is pointless).


My second issue is that this shouldn't raise an error at all.  It should be possible for functions to be registered as subclasses of ABCs.  This would simplify some code of mine that uses functions and classes interchangeably, and I can see no "real" reason why it shouldn't work.  From the user's point of view, my library provides a bunch of "things" that all look the same (they are provided with arguments and do stuff).  Whether these are constructors or functions is irrelevant...  and yet my code has to handle constructors and functions differently simply because of the errors here.

What I suspect I will do is have my own hash table, and forget ABCs, but that is a pity because these functions really do work as constructors (they are factories) and so the idea of them being subclasses of an ABC helps clarify my code.
msg98400 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-01-27 02:18
Fixed first bug in r77789. The second issue is a separate feature request.
msg98408 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2010-01-27 09:35
...and for the second feature, Andrew may wish to look at zope.component, which provides for this already.
History
Date User Action Args
2022-04-11 14:56:56adminsetgithub: 52040
2010-01-27 09:35:35cjw296setnosy: + cjw296
messages: + msg98408
2010-01-27 02:18:18benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg98400

resolution: fixed
2010-01-26 22:53:28acookecreate