[Python-bugs-list] [ python-Bugs-749480 ] strange __subclasses__ behaviour

SourceForge.net noreply@sourceforge.net
Sat, 14 Jun 2003 07:28:06 -0700


Bugs item #749480, was opened at 2003-06-05 13:30
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=749480&group_id=5470

Category: Type/class unification
Group: Python 2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Gerrit Holl (gerrit)
Assigned to: Nobody/Anonymous (nobody)
Summary: strange  __subclasses__ behaviour

Initial Comment:
I am not entirely sure whether this is a bug, because I
can't find documentation on __subclasses__ and am
unable to read the source (don't know C). But the name
__subclasses__ implies that a collection of all
subclasses would be returned; however, it doesn't on my
system. It seems as if some subclasses are only listed
*after* they have been looked up in the subclasses'
__bases__, while others are included without that:

$ python
Python 2.3b1+ (#2, Jun  4 2003, 17:16:59)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
  0 >>> float in object.__subclasses__()
False
  1 >>> object in float.__bases__
True
  2 >>> float in object.__subclasses__()
True  3 >>> object.__subclasses__
<built-in method __subclasses__ of type object at
0x8107d60>
  4 >>> object.__subclasses__()
[<type 'type'>, <type 'int'>, <type 'basestring'>,
<type 'list'>, <type 'NoneType'>, <type
'NotImplementedType'>, <type 'module'>, <type
'zipimport.zipimporter'>, <type 'posix.stat_result'>,
<type 'posix.statvfs_result'>, <type 'dict'>, <type
'function'>, <type 'file'>, <type 'float'>, <type
'dictproxy'>]
  5 >>> long in object.__subclasses__()
False
  6 >>> long()
0L
  7 >>> long in object.__subclasses__()
False
  8 >>> long.__bases__
(<type 'object'>,)
  9 >>> long in object.__subclasses__()
True
$ python -c "print object.__subclasses__()"
[<type 'type'>, <type 'int'>, <type 'basestring'>,
<type 'list'>, <type 'NoneType'>, <type
'NotImplementedType'>, <type 'module'>, <type
'zipimport.zipimporter'>, <type 'posix.stat_result'>,
<type 'posix.statvfs_result'>, <type 'dict'>, <type
'function'>, <type 'file'>]
$ python -S -c "print object.__subclasses__()"
[<type 'type'>, <type 'int'>, <type 'basestring'>,
<type 'list'>, <type 'NoneType'>, <type
'NotImplementedType'>, <type 'module'>, <type
'zipimport.zipimporter'>, <type 'function'>, <type
'posix.stat_result'>, <type 'posix.statvfs_result'>,
<type 'dict'>]


----------------------------------------------------------------------

>Comment By: Martin v. L÷wis (loewis)
Date: 2003-06-14 16:28

Message:
Logged In: YES 
user_id=21627

This is not a bug. A type is added to __subclasses__ of its
base once it gets "readied". When and if that happens for a
certain type is implementation-defined.

----------------------------------------------------------------------

Comment By: Gerrit Holl (gerrit)
Date: 2003-06-05 13:36

Message:
Logged In: YES 
user_id=13298

I accidently pressed enter to early, here is some more
information:

$ python2.2 -S -c "print object.__subclasses__()"
[<type 'type'>, <type 'list'>, <type 'NoneType'>, <type
'NotImplementedType'>, <type 'module'>]

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=749480&group_id=5470