Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
46441912
Commit
46441912
authored
Jul 28, 2015
by
Tzer-jen Wei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for list, set, dict
parent
d47a25b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
5 deletions
+88
-5
Cython/Tests/TestJediTyper.py
Cython/Tests/TestJediTyper.py
+86
-3
Tools/jedi-typer.py
Tools/jedi-typer.py
+2
-2
No files found.
Cython/Tests/TestJediTyper.py
View file @
46441912
...
@@ -66,9 +66,6 @@ class TestJediTyper(TransformTest):
...
@@ -66,9 +66,6 @@ class TestJediTyper(TransformTest):
a = i + 1
a = i + 1
'''
'''
types
=
self
.
_test
(
code
)
types
=
self
.
_test
(
code
)
if
not
types
:
# old Jedi version
return
self
.
assertIn
((
None
,
(
1
,
0
)),
types
)
self
.
assertIn
((
None
,
(
1
,
0
)),
types
)
variables
=
types
.
pop
((
None
,
(
1
,
0
)))
variables
=
types
.
pop
((
None
,
(
1
,
0
)))
self
.
assertFalse
(
types
)
self
.
assertFalse
(
types
)
...
@@ -120,6 +117,92 @@ class TestJediTyper(TransformTest):
...
@@ -120,6 +117,92 @@ class TestJediTyper(TransformTest):
self
.
assertFalse
(
types
)
self
.
assertFalse
(
types
)
self
.
assertEqual
({
'a'
:
set
([
'int'
]),
'i'
:
set
([
'int'
])},
variables
)
self
.
assertEqual
({
'a'
:
set
([
'int'
]),
'i'
:
set
([
'int'
])},
variables
)
def
test_typing_global_list
(
self
):
code
=
'''
\
a = [x for x in range(10)]
b = list(range(10))
c = a + b
d = [0]*10
'''
types
=
self
.
_test
(
code
)
self
.
assertIn
((
None
,
(
1
,
0
)),
types
)
variables
=
types
.
pop
((
None
,
(
1
,
0
)))
self
.
assertFalse
(
types
)
self
.
assertEqual
({
'a'
:
set
([
'list'
]),
'b'
:
set
([
'list'
]),
'c'
:
set
([
'list'
]),
'd'
:
set
([
'list'
])},
variables
)
def
test_typing_function_list
(
self
):
code
=
'''
\
def func(x):
a = [[], []]
b = [0]* 10 + a
c = a[0]
print(func([0]*100))
'''
types
=
self
.
_test
(
code
)
self
.
assertIn
((
'func'
,
(
1
,
0
)),
types
)
variables
=
types
.
pop
((
'func'
,
(
1
,
0
)))
self
.
assertFalse
(
types
)
self
.
assertEqual
({
'a'
:
set
([
'list'
]),
'b'
:
set
([
'list'
]),
'c'
:
set
([
'list'
]),
'x'
:
set
([
'list'
])},
variables
)
def
test_typing_global_dict
(
self
):
code
=
'''
\
a = dict()
b = {i: i**2 for i in range(10)}
c = a
'''
types
=
self
.
_test
(
code
)
self
.
assertIn
((
None
,
(
1
,
0
)),
types
)
variables
=
types
.
pop
((
None
,
(
1
,
0
)))
self
.
assertFalse
(
types
)
self
.
assertEqual
({
'a'
:
set
([
'dict'
]),
'b'
:
set
([
'dict'
]),
'c'
:
set
([
'dict'
])},
variables
)
def
test_typing_function_dict
(
self
):
code
=
'''
\
def func(x):
a = dict()
b = {i: i**2 for i in range(10)}
c = x
print(func({1:2, 'x':7}))
'''
types
=
self
.
_test
(
code
)
self
.
assertIn
((
'func'
,
(
1
,
0
)),
types
)
variables
=
types
.
pop
((
'func'
,
(
1
,
0
)))
self
.
assertFalse
(
types
)
self
.
assertEqual
({
'a'
:
set
([
'dict'
]),
'b'
:
set
([
'dict'
]),
'c'
:
set
([
'dict'
]),
'x'
:
set
([
'dict'
])},
variables
)
def
test_typing_global_set
(
self
):
code
=
'''
\
a = set()
# b = {i for i in range(10)} # jedi does not support set comprehension yet
c = a
d = {1,2,3}
e = a | b
'''
types
=
self
.
_test
(
code
)
self
.
assertIn
((
None
,
(
1
,
0
)),
types
)
variables
=
types
.
pop
((
None
,
(
1
,
0
)))
self
.
assertFalse
(
types
)
self
.
assertEqual
({
'a'
:
set
([
'set'
]),
'c'
:
set
([
'set'
]),
'd'
:
set
([
'set'
]),
'e'
:
set
([
'set'
])},
variables
)
def
test_typing_function_set
(
self
):
code
=
'''
\
def func(x):
a = set()
# b = {i for i in range(10)} # jedi does not support set comprehension yet
c = a
d = a | b
print(func({1,2,3}))
'''
types
=
self
.
_test
(
code
)
self
.
assertIn
((
'func'
,
(
1
,
0
)),
types
)
variables
=
types
.
pop
((
'func'
,
(
1
,
0
)))
self
.
assertFalse
(
types
)
self
.
assertEqual
({
'a'
:
set
([
'set'
]),
'c'
:
set
([
'set'
]),
'd'
:
set
([
'set'
]),
'x'
:
set
([
'set'
])},
variables
)
class
TestTypeInjection
(
TestJediTyper
):
class
TestTypeInjection
(
TestJediTyper
):
"""
"""
...
...
Tools/jedi-typer.py
View file @
46441912
...
@@ -11,7 +11,7 @@ from itertools import chain
...
@@ -11,7 +11,7 @@ from itertools import chain
import
jedi
import
jedi
from
jedi.parser.tree
import
Module
,
ImportName
from
jedi.parser.tree
import
Module
,
ImportName
from
jedi.evaluate.representation
import
Function
,
Instance
,
Class
from
jedi.evaluate.representation
import
Function
,
Instance
,
Class
from
jedi.evaluate.iterable
import
Array
,
Generator
,
GeneratorComprehension
from
jedi.evaluate.iterable
import
Array
Mixin
,
GeneratorComprehension
from
Cython.Utils
import
open_source_file
from
Cython.Utils
import
open_source_file
...
@@ -52,7 +52,7 @@ def analyse(source_path=None, code=None):
...
@@ -52,7 +52,7 @@ def analyse(source_path=None, code=None):
type_name
=
'object'
type_name
=
'object'
else
:
else
:
type_name
=
name_type
.
base
.
obj
.
__name__
type_name
=
name_type
.
base
.
obj
.
__name__
elif
isinstance
(
name_type
,
Array
):
elif
isinstance
(
name_type
,
Array
Mixin
):
type_name
=
name_type
.
type
type_name
=
name_type
.
type
elif
isinstance
(
name_type
,
GeneratorComprehension
):
elif
isinstance
(
name_type
,
GeneratorComprehension
):
type_name
=
None
type_name
=
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment