mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
removed pr.String and pr.Number in favor of the more general pr.Literal
This commit is contained in:
@@ -92,14 +92,14 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
if len(key_expression_list) != 1: # cannot deal with complex strings
|
if len(key_expression_list) != 1: # cannot deal with complex strings
|
||||||
continue
|
continue
|
||||||
key = key_expression_list[0]
|
key = key_expression_list[0]
|
||||||
if isinstance(key, pr.String):
|
if isinstance(key, pr.Literal):
|
||||||
str_key = key.value
|
key = key.value
|
||||||
elif isinstance(key, pr.Name):
|
elif isinstance(key, pr.Name):
|
||||||
str_key = str(key)
|
key = str(key)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if mixed_index == str_key:
|
if mixed_index == key:
|
||||||
index = i
|
index = i
|
||||||
break
|
break
|
||||||
if index is None:
|
if index is None:
|
||||||
|
|||||||
@@ -1069,9 +1069,7 @@ class Statement(Simple):
|
|||||||
|
|
||||||
is_literal = token_type in [tokenize.STRING, tokenize.NUMBER]
|
is_literal = token_type in [tokenize.STRING, tokenize.NUMBER]
|
||||||
if isinstance(tok, Name) or is_literal:
|
if isinstance(tok, Name) or is_literal:
|
||||||
cls = Call
|
cls = Literal if is_literal else Call
|
||||||
if is_literal:
|
|
||||||
cls = String if token_type == tokenize.STRING else Number
|
|
||||||
|
|
||||||
call = cls(self._sub_module, tok, start_pos, end_pos, self)
|
call = cls(self._sub_module, tok, start_pos, end_pos, self)
|
||||||
if is_chain:
|
if is_chain:
|
||||||
@@ -1243,14 +1241,6 @@ class Literal(StatementElement):
|
|||||||
return "<%s: %s>" % (type(self).__name__, s)
|
return "<%s: %s>" % (type(self).__name__, s)
|
||||||
|
|
||||||
|
|
||||||
class String(Literal):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Number(Literal):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Array(StatementElement):
|
class Array(StatementElement):
|
||||||
"""
|
"""
|
||||||
Describes the different python types for an array, but also empty
|
Describes the different python types for an array, but also empty
|
||||||
|
|||||||
@@ -37,15 +37,15 @@ class TestCallAndName():
|
|||||||
|
|
||||||
def test_literal_type(self):
|
def test_literal_type(self):
|
||||||
literal = self.get_call('1.0')
|
literal = self.get_call('1.0')
|
||||||
assert isinstance(literal, pr.Number)
|
assert isinstance(literal, pr.Literal)
|
||||||
assert type(literal.value) == float
|
assert type(literal.value) == float
|
||||||
|
|
||||||
literal = self.get_call('1')
|
literal = self.get_call('1')
|
||||||
assert isinstance(literal, pr.Number)
|
assert isinstance(literal, pr.Literal)
|
||||||
assert type(literal.value) == int
|
assert type(literal.value) == int
|
||||||
|
|
||||||
literal = self.get_call('"hello"')
|
literal = self.get_call('"hello"')
|
||||||
assert isinstance(literal, pr.String)
|
assert isinstance(literal, pr.Literal)
|
||||||
assert literal.value == 'hello'
|
assert literal.value == 'hello'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user