[Python-Dev] type.__subclasses__() doesn't work
Hello, Just noticed the following quirk: type.__subclasses__() Traceback (most recent call last): File stdin, line 1, in module TypeError: descriptor '__subclasses__' of 'type' object needs an argument Yet it would be nice to know about the subclasses of type. Regards Antoine. ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] type.__subclasses__() doesn't work
On Wed, Oct 09, 2013 at 12:20:18PM +0200, Antoine Pitrou wrote: Hello, Just noticed the following quirk: type.__subclasses__() Traceback (most recent call last): File stdin, line 1, in module TypeError: descriptor '__subclasses__' of 'type' object needs an argument Yet it would be nice to know about the subclasses of type. py type.__subclasses__(type) [class 'abc.ABCMeta', class 'string._TemplateMetaclass'] -- Steven ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] type.__subclasses__() doesn't work
Steven D'Aprano wrote: On Wed, Oct 09, 2013 at 12:20:18PM +0200, Antoine Pitrou wrote: Hello, Just noticed the following quirk: type.__subclasses__() Traceback (most recent call last): File stdin, line 1, in module TypeError: descriptor '__subclasses__' of 'type' object needs an argument Yet it would be nice to know about the subclasses of type. py type.__subclasses__(type) [class 'abc.ABCMeta', class 'string._TemplateMetaclass'] The underlying problem seems to be that there is no helper function to bypass the instance attribute. Compare: class T(type): ... def __len__(self): return 0 ... class A(metaclass=T): ... def __len__(self): return 1 ... A.__len__() Traceback (most recent call last): File stdin, line 1, in module TypeError: __len__() missing 1 required positional argument: 'self' len(A) 0 So should there be a subclasses() function, in the operator module perhaps? ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] type.__subclasses__() doesn't work
On 10/09/2013 02:22 PM, Peter Otten wrote: py type.__subclasses__(type) [class 'abc.ABCMeta', class 'string._TemplateMetaclass'] The underlying problem seems to be that there is no helper function to bypass the instance attribute. Note that the problem is specific to the type type, which is its own metatype. With other types that get __subclasses__ from type, is no problem with just calling __subclasses__(): int.__subclasses__() [type 'bool'] ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com