mdickinson / refcycle

Support for displaying and analyzing reference graphs of Python objects.
Apache License 2.0
15 stars 1 forks source link

AttributeError: 'WinFunctionType' object has no attribute '__name__' #25

Closed mdickinson closed 7 years ago

mdickinson commented 10 years ago

When converting to an annotated graph: not every object type has a __name__ attribute; we need some kind of sensible fallback.

mdickinson commented 10 years ago

Partial traceback:

  File "C:\Python27\lib\site-packages\envisage\ui\tasks\action\exit_action.py",
line 35, in perform
    json = snapshot.export_json().encode('utf-8')
  File "c:\users\factory\refcycle\refcycle\object_graph.py", line 324, in export
_json
    return self.annotated().export_json()
  File "c:\users\factory\refcycle\refcycle\object_graph.py", line 275, in annota
ted
    for vertex in self.vertices
  File "c:\users\factory\refcycle\refcycle\annotations.py", line 142, in object_
annotation
    obj.__func__.__name__,
AttributeError: 'WinFunctionType' object has no attribute '__name__'
mdickinson commented 10 years ago

Related:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pyface\ui\qt4\action\action_item.py", line
 163, in _qt4_on_triggered
    self.controller.perform(action, action_event)
  File "C:\Python27\lib\site-packages\pyface\tasks\action\task_action_controller
.py", line 31, in perform
    return action.perform(event)
  File "C:\Python27\lib\site-packages\envisage\ui\tasks\action\exit_action.py",
line 35, in perform
    json = snapshot.export_json().encode('utf-8')
  File "c:\users\factory\refcycle\refcycle\object_graph.py", line 324, in export
_json
    return self.annotated().export_json()
  File "c:\users\factory\refcycle\refcycle\object_graph.py", line 275, in annota
ted
    for vertex in self.vertices
  File "c:\users\factory\refcycle\refcycle\annotations.py", line 141, in object_
annotation
    obj.im_class.__name__,
AttributeError: 'NoneType' object has no attribute '__name__'
mdickinson commented 10 years ago

Easiest way to reproduce for testing purposes is to use ctypes:

>>> def py_cmp_func(a, b):
...     print "py_cmp_func", a, b
...     return 0
... 
>>> from ctypes import *
>>> CMPFUNC = CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
>>> cmp_func = CMPFUNC(py_cmp_func)
>>> cmp_func
<CFunctionType object at 0x1004ab460>
>>> cmp_func.__name__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'CFunctionType' object has no attribute '__name__'
mdickinson commented 7 years ago

The related issue reported above is fixed in #56. It was caused by a bound method object whose im_class attribute was None. Such objects can be created using types.MethodType, by omitting the third argument.