msg55663 - (view) |
Author: Mark Summerfield (mark) * |
Date: 2007-09-05 15:22 |
GvR asked me to add this to the bug tracker. If you do this: class A(ABCMeta): pass A.register(list) you get this error message: Traceback (most recent call last): File "", line 1, in RuntimeError: maximum recursion depth exceeded in __instancecheck__ This is not very helpful. You probably meant to write: class A(metaclass=ABCMeta): pass Perhaps a warning message like this would be better: "register() should not be called on an ABCMeta subclass; maybe you forgot the metaclass keyword argument when declaring the class?" |
|
|
msg57742 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2007-11-21 22:47 |
This would be easier to fix if we didn't have unbound methods. I'm going to ask the py3k list if anybody really cares about having those. |
|
|
msg57980 - (view) |
Author: Christian Heimes (christian.heimes) *  |
Date: 2007-11-30 13:43 |
Are you fine with the error message or do you have a better one? Index: Lib/abc.py =================================================================== --- Lib/abc.py (Revision 59228) +++ Lib/abc.py (Arbeitskopie) @@ -137,8 +137,12 @@ cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter return cls - def register(cls, subclass): + def register(cls, subclass=None): """Register a virtual subclass of an ABC.""" + if subclass is None: + raise TypeError("register() cannot be called on an ABCMeta " + "subclass. Maybe you forgot the metaclass keyword argument " + "when declaring the class?") if not isinstance(cls, type): raise TypeError("Can only register classes") if issubclass(subclass, cls): |
|
|
msg57983 - (view) |
Author: Christian Heimes (christian.heimes) *  |
Date: 2007-11-30 14:33 |
Fixed in r59233. Please adjust the error message if you don't like it. TypeError: register() cannot be called on an ABCMeta subclass, use class Example(metaclass=abc.ABCMeta) instead. |
|
|
msg57985 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2007-11-30 15:07 |
Please roll this back. The error message you added is inappropriate when the parameter to a legitimate register() call is omitted, e.g. collections.Sequence.register() Since we got rid of unbound methods, the infinite recursion is gone; that's a good enough fix, there are tons of other situations where confusion between class and instance (or between metaclass and class) causes confusing error messages. |
|
|
msg57986 - (view) |
Author: Mark Summerfield (mark) * |
Date: 2007-11-30 15:29 |
On 2007-11-30, Christian Heimes wrote: > Christian Heimes added the comment: > > Fixed in r59233. Please adjust the error message if you don't like it. > > TypeError: register() cannot be called on an ABCMeta subclass, use class > Example(metaclass=abc.ABCMeta) instead. I think it is fine---but seems that GvR doesn't want it! |
|
|
msg57987 - (view) |
Author: Christian Heimes (christian.heimes) *  |
Date: 2007-11-30 15:32 |
I've reverted the changes. |
|
|