Nicer usage of py_call within InstanceElement and Python 2.7 compatibility

This commit is contained in:
Dave Halter
2014-07-30 17:00:16 +02:00
parent 7cc35fe0b8
commit 723d1e4631
2 changed files with 9 additions and 6 deletions

View File

@@ -14,7 +14,7 @@ import copy
import os
import pkgutil
from jedi._compatibility import use_metaclass, unicode
from jedi._compatibility import use_metaclass, unicode, Python3Method
from jedi.parser import representation as pr
from jedi.parser.tokenize import Token
from jedi import debug
@@ -251,13 +251,11 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
return isinstance(self.var, cls)
def py__call__(self, evaluator, params):
# TODO this should be working nicer.
# TODO Why are CompiledObject and Instance even InstanceObjects?
if isinstance(self.var, (compiled.CompiledObject, Instance)):
return self.var.py__call__(evaluator, params)
if self.is_generator:
return [iterable.Generator(evaluator, self, params)]
stmts = FunctionExecution(evaluator, self, params).get_return_types()
return stmts
else:
return Function.py__call__(self, evaluator, params)
def __repr__(self):
return "<%s of %s>" % (type(self).__name__, self.var)
@@ -422,6 +420,7 @@ class Function(use_metaclass(CachedMetaClass, pr.IsScope)):
def get_magic_function_scope(self):
return compiled.magic_function_class
@Python3Method
def py__call__(self, evaluator, params):
if self.is_generator:
return [iterable.Generator(evaluator, self, params)]

View File

@@ -6,6 +6,10 @@ import pytest
from jedi import Script
from jedi._compatibility import is_py26
# The namedtuple is different for different Python2.7 versions. Some versions
# are missing the attribute `_class_template`.
pytestmark = pytest.mark.skipif('sys.version_info[0] < 3')
@pytest.mark.parametrize(['letter', 'expected'], [
('n', ['name']),