Issue 1109: Warning required when calling register() on an ABCMeta subclass (original) (raw)

Created on 2007-09-05 15:22 by mark, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2007-11-30 15:32
I've reverted the changes.
History
Date User Action Args
2022-04-11 14:56:26 admin set github: 45450
2008-01-06 22:29:44 admin set keywords: - py3kversions: Python 3.0
2007-11-30 15:32:52 christian.heimes set status: open -> closedmessages: +
2007-11-30 15:29:49 mark set messages: +
2007-11-30 15:07:48 gvanrossum set status: closed -> openassignee: gvanrossum -> christian.heimesmessages: +
2007-11-30 14:33:35 christian.heimes set status: open -> closedresolution: fixedmessages: +
2007-11-30 13:43:22 christian.heimes set keywords: + py3k, patchnosy: + christian.heimesmessages: + components: + Library (Lib), - Interpreter Core
2007-11-21 22:47:55 gvanrossum set messages: +
2007-09-17 08:11:24 jafo set priority: normalassignee: gvanrossumnosy: + gvanrossum
2007-09-05 15:22:18 mark create