mdickinson / refcycle

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

Make annotations less fragile #60

Open mdickinson opened 7 years ago

mdickinson commented 7 years ago

The annotations code is somewhat fragile: it makes assumptions that are often violated by real-world code (for example, that every bound method in Python 2 will have a non-None im_class attribute, or that every function will have a __name__ attribute).

It would probably be worth doing an except Exception around each annotation, logging any exceptions, and continuing.

VojtechFried commented 7 years ago

One more thing to consider: expired weakrefs. E.g. File "C:\Python36\lib\site-packages\refcycle\object_graph.py", line 339, in export_json self.annotated().export_json(filename=filename) File "C:\Python36\lib\site-packages\refcycle\object_graph.py", line 279, in annotated for vertex in self.vertices File "C:\Python36\lib\site-packages\refcycle\object_graph.py", line 279, in for vertex in self.vertices File "C:\Python36\lib\site-packages\refcycle\annotations.py", line 172, in object_annotation if isinstance(obj, BASE_TYPES): ReferenceError: weakly-referenced object no longer exists

mdickinson commented 7 years ago

Nice catch; thanks. Do you happen to have a short snippet that reproduces (and that I can turn into a testcase)?

mdickinson commented 7 years ago

Opened #78 for the bug reported by @VojtechFried.