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 1/4] 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__) From 9d5cc0be065bf45286a6d160478c2cf4d8a96b2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Gouzien?= Date: Sat, 6 May 2017 14:14:56 +0200 Subject: [PATCH 2/4] Test that no repr() can slow down completion. Was reported with issue #919. --- test/test_speed.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_speed.py b/test/test_speed.py index dcb69840..73dda181 100644 --- a/test/test_speed.py +++ b/test/test_speed.py @@ -51,3 +51,19 @@ class TestSpeed(TestCase): with open('speed/precedence.py') as f: line = len(f.read().splitlines()) assert jedi.Script(line=line, path='speed/precedence.py').goto_definitions() + + @_check_speed(0.1) + def test_no_repr_computation(self): + """ + For Interpreter completion aquisition of sourcefile can trigger + unwanted computation of repr(). Exemple : big pandas data. + See issue #919. + """ + class Slow_repr(): + "class to test what happens if __repr__ is very slow." + def some_method(self): + pass + def __repr__(self): + time.sleep(0.2) + test = Slow_repr() + jedi.Interpreter('test.som', [locals()]).completions() From 405a3397193401e89893f92ba725857547b89224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Gouzien?= Date: Sat, 6 May 2017 14:16:06 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Add=20author=20=C3=89lie=20Gouzien.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AUTHORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index b5619dcb..52204a8b 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -43,6 +43,7 @@ bstaint (@bstaint) Mathias Rav (@Mortal) Daniel Fiterman (@dfit99) Simon Ruggier (@sruggier) +Élie Gouzien (@ElieGouzien) Note: (@user) means a github user name. From 80fbdec1da486fbada57e9a470222943c5301ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Gouzien?= Date: Sat, 6 May 2017 14:28:11 +0200 Subject: [PATCH 4/4] Corrected test class name. --- test/test_speed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_speed.py b/test/test_speed.py index 73dda181..8d5bc9a3 100644 --- a/test/test_speed.py +++ b/test/test_speed.py @@ -59,11 +59,11 @@ class TestSpeed(TestCase): unwanted computation of repr(). Exemple : big pandas data. See issue #919. """ - class Slow_repr(): + class SlowRepr(): "class to test what happens if __repr__ is very slow." def some_method(self): pass def __repr__(self): time.sleep(0.2) - test = Slow_repr() + test = SlowRepr() jedi.Interpreter('test.som', [locals()]).completions()