mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
move set comprehension tests to comletion/comprehensions.py
This commit is contained in:
@@ -50,6 +50,13 @@ left
|
|||||||
##? str()
|
##? str()
|
||||||
{a-1:b for a,b in {1:'a', 3:1.0}.items()}[0]
|
{a-1:b for a,b in {1:'a', 3:1.0}.items()}[0]
|
||||||
|
|
||||||
|
# with a set literal
|
||||||
|
#? int()
|
||||||
|
[a for a in {1, 2, 3}][0]
|
||||||
|
|
||||||
|
##? int()
|
||||||
|
{a for a in range(10)}[0]
|
||||||
|
|
||||||
# list comprehensions should also work in combination with functions
|
# list comprehensions should also work in combination with functions
|
||||||
def listen(arg):
|
def listen(arg):
|
||||||
for x in arg:
|
for x in arg:
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
from textwrap import dedent
|
|
||||||
|
|
||||||
from jedi import names
|
|
||||||
|
|
||||||
|
|
||||||
def get_scope_and_evaluator(source):
|
|
||||||
d = names(dedent(source))[0]
|
|
||||||
return d.parent()._definition, d._evaluator
|
|
||||||
|
|
||||||
def find_types(s):
|
|
||||||
scope, evaluator = get_scope_and_evaluator(s)
|
|
||||||
return evaluator.find_types(scope, s[0])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_comprehensions():
|
|
||||||
"""
|
|
||||||
test list/set/generator/dict comprehension syntax
|
|
||||||
"""
|
|
||||||
|
|
||||||
s = "a = [i for i in range(10)]"
|
|
||||||
assert len(find_types(s)) == 1
|
|
||||||
|
|
||||||
s = "a = [i for i in range(10)]"
|
|
||||||
assert len(find_types(s)) == 1
|
|
||||||
|
|
||||||
s = "a = {i:i for i in range(10)}"
|
|
||||||
assert len(find_types(s)) == 1
|
|
||||||
|
|
||||||
s = "a = {i for i in range(10)}"
|
|
||||||
assert len(find_types(s)) == 1
|
|
||||||
Reference in New Issue
Block a user