From a78769954db5101f1202ce747697dc74b1ba13a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Gouzien?= Date: Sat, 6 May 2017 13:33:36 +0200 Subject: [PATCH] Check whether inspect.getfile will raise a TypeError and anticipate it. Anticipate the raise of TypeError from inspect.getfile to prevent the computation of repr() for the error message wich is not used. Useful for some big pandas arrays. Fix tentative of #919. --- jedi/evaluate/compiled/mixed.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jedi/evaluate/compiled/mixed.py b/jedi/evaluate/compiled/mixed.py index dfb49657..1390ea47 100644 --- a/jedi/evaluate/compiled/mixed.py +++ b/jedi/evaluate/compiled/mixed.py @@ -116,8 +116,21 @@ def _load_module(evaluator, path, python_object): return module +def source_findable(python_object): + """Check if inspect.getfile has a chance to find the source.""" + return (inspect.ismodule(python_object) or + inspect.isclass(python_object) or + inspect.ismethod(python_object) or + inspect.isfunction(python_object) or + inspect.istraceback(python_object) or + inspect.isframe(python_object) or + inspect.iscode(python_object)) + + def find_syntax_node_name(evaluator, python_object): try: + if not source_findable(python_object): + raise TypeError # Prevents computation of `repr` within inspect. path = inspect.getsourcefile(python_object) except TypeError: # The type might not be known (e.g. class_with_dict.__weakref__)