[New-bugs-announce] [issue7792] Errors registering non-classes with ABCs
report at bugs.python.org
Tue Jan 26 23:53:30 CET 2010
New submission from andrew cooke <andrew at acooke.org>:
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.
components: Library (Lib)
title: Errors registering non-classes with ABCs
versions: Python 3.2
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce