New submission from andrew cooke <[email protected]>:

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)
messages: 98387
nosy: acooke
severity: normal
status: open
title: Errors registering non-classes with ABCs
type: behavior
versions: Python 3.2

_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue7792>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to