CompiledObject.name returns a Name now, not a string. This is more consistent with the Jedi design and doesn't lead to bugs while ducktyping.

This commit is contained in:
Dave Halter
2014-09-03 19:43:21 +02:00
parent 18204c4c19
commit bb5ffe9343
5 changed files with 8 additions and 10 deletions

View File

@@ -652,7 +652,7 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)):
typ = d.type()
if typ == 'instance':
typ = 'class' # The description should be similar to Py objects.
d = typ + ' ' + d.name
d = typ + ' ' + d.name.get_code()
elif isinstance(d, iterable.Array):
d = 'class ' + d.type
elif isinstance(d, (pr.Class, er.Class, er.Instance)):

View File

@@ -188,12 +188,10 @@ class CompiledObject(Base):
pass # self.obj maynot have an __iter__ method.
return result
"""
@property
def name(self):
# might not exist sometimes (raises AttributeError)
return self._cls().obj.__name__
"""
return FakeName(self._cls().obj.__name__, self)
def _execute_function(self, evaluator, params):
if self.type() != 'function':

View File

@@ -213,7 +213,7 @@ def _literals_to_types(evaluator, result):
if is_literal(r):
# Literals are only valid as long as the operations are
# correct. Otherwise add a value-free instance.
cls = builtin.get_by_name(r.name)
cls = builtin.get_by_name(r.name.get_code())
result[i] = evaluator.execute(cls)[0]
return list(set(result))

View File

@@ -84,7 +84,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
"""
def __init__(self, evaluator, base, var_args=()):
super(Instance, self).__init__(evaluator, base, var_args)
if str(base.name) in ['list', 'set'] \
if base.name.get_code() in ['list', 'set'] \
and compiled.builtin == base.get_parent_until():
# compare the module path with the builtin name.
self.var_args = iterable.check_array_instances(evaluator, self)

View File

@@ -90,14 +90,14 @@ def test_module():
module = Parser(u('asdf'), 'example.py', no_docstr=True).module
name = module.name
assert str(name) == 'example'
assert name.start_pos == (0, 0)
assert name.end_pos == (0, 7)
assert name.start_pos == (1, 0)
assert name.end_pos == (1, 7)
module = Parser(u('asdf'), no_docstr=True).module
name = module.name
assert str(name) == ''
assert name.start_pos == (0, 0)
assert name.end_pos == (0, 0)
assert name.start_pos == (1, 0)
assert name.end_pos == (1, 0)
def test_end_pos():