[issue21113] Error usage of class.__bases__()

Lotus Qin report at bugs.python.org
Mon Mar 31 16:30:34 CEST 2014


New submission from Lotus Qin:

function in urllib.request.build_opener()

    def isclass(obj):
        return isinstance(obj, type) or hasattr(obj, "__bases__")

should it be `obj` or `obj.__class__`?

cause in the man of 3.4, there is only `class.__bases__`, but the code there may function like `instance.__bases__`.

=======

# my code behave like this: 

cookie = http.cookiejar.CookieJar()
cookie_handler = urllib.request.HTTPCookieProcessor(cookie)
opener = urllib.request.build_opener(cookie_handler)

# the variable `skip` in `build_opener` will be empty cause `isclass(obj)` always return false. 

cookie_handler.__bases__
AttributeError: 'HTTPCookieProcessor' object has no attribute '__bases__'

cookie_handler.__class__.__bases__
(<class 'urllib.request.BaseHandler'>,)

----------
components: Library (Lib)
messages: 215241
nosy: ZealotuS
priority: normal
severity: normal
status: open
title: Error usage of class.__bases__()
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21113>
_______________________________________


More information about the Python-bugs-list mailing list