1
0
forked from VimPlug/jedi

Way better support for instantiated classes in REPL

Fixes several issues:

- It was not possible to correctly trace where instances were coming from in a
  REPL. This led to them being pretty much ignored.
- Instances were then just treated as classes and not as actual instances in
  MixedObjects. (However since they were ignored in the first place this
  wasn't really an issue).
- Avoiding the repr bug https://github.com/python/cpython/pull/2132/files in
  Jedi is working a bit differently. We're just never accessing Objects
  directly. This should work around 99.99% of the cases were people are using
  this stuff.

Fixes #872
This commit is contained in:
Dave Halter
2017-09-15 01:55:00 +02:00
parent 63edbdcc5b
commit 9dd2027299
4 changed files with 60 additions and 11 deletions

View File

@@ -171,11 +171,13 @@ def test_slice():
def test_getitem_side_effects():
class Foo2():
def __getitem__(self, index):
# possible side effects here, should therefore not call this.
# Possible side effects here, should therefore not call this.
if True:
raise NotImplementedError()
return index
foo = Foo2()
_assert_interpreter_complete('foo[0].', locals(), [])
_assert_interpreter_complete('foo["asdf"].upper', locals(), ['upper'])
def test_property_error_oldstyle():
@@ -252,3 +254,39 @@ def test_completion_param_annotations():
assert a._goto_definitions() == []
assert [d.name for d in b._goto_definitions()] == ['str']
assert set([d.name for d in c._goto_definitions()]) == set(['int', 'float'])
def test_more_complex_instances():
class Something:
def foo(self, other):
return self
class Base():
def wow(self):
return Something()
#script = jedi.Interpreter('Base().wow().foo', [locals()])
#c, = script.completions()
#assert c.name == 'foo'
x = Base()
script = jedi.Interpreter('x.wow().foo', [locals()])
c, = script.completions()
assert c.name == 'foo'
def test_repr_execution_issue():
"""
Anticipate inspect.getfile executing a __repr__ of all kinds of objects.
See also #919.
"""
class ErrorRepr:
def __repr__(self):
raise Exception('xyz')
er = ErrorRepr()
script = jedi.Interpreter('er', [locals()])
d, = script.goto_definitions()
assert d.name == 'ErrorRepr'
assert d.type == 'instance'