classification
Title: inspect.isclass() fails with custom __getattr__
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, jkloth (2)
Priority: normal Keywords

Created on 2005-06-21 20:20 by jkloth, last changed 2009-01-17 22:28 by benjamin.peterson.

Messages (2)
msg60765 - (view) Author: Jeremy Kloth (jkloth) Date: 2005-06-21 20:20
inspect.isclass() can return True for instances of classes   
which define a __getattr__ method.  For example:   
   
>>> class Namespace(unicode):   
...    def __getattr__(self, attr):   
...       return '<%s>' % (self + attr)   
...   
>>> inspect.isclass(Namespace('foo'))   
True   
   
Changing inspect.isclass() to:   
  return isinstance(object, (types.ClassType, type))   
solves this issue.   
   
The check for __bases__ is no longer need due to   
type/class unification.   
msg80054 - (view) Author: Benjamin Peterson (benjamin.peterson) Date: 2009-01-17 22:28
Finally fixed in r68676.
History
Date User Action Args
2009-01-17 22:28:08benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg80054
nosy: + benjamin.peterson
2005-06-21 20:20:01jklothcreate