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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
e7c7730c
Commit
e7c7730c
authored
May 23, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement type inference for stared unpacking targets as list.
parent
dbc563c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+5
-2
tests/run/type_inference.pyx
tests/run/type_inference.pyx
+29
-0
No files found.
Cython/Compiler/FlowControl.py
View file @
e7c7730c
...
...
@@ -778,8 +778,11 @@ class ControlFlowAnalysis(CythonTransform):
self
.
flow
.
mark_assignment
(
lhs
,
rhs
,
entry
)
elif
lhs
.
is_sequence_constructor
:
for
i
,
arg
in
enumerate
(
lhs
.
args
):
if
not
rhs
or
arg
.
is_starred
:
item_node
=
None
if
arg
.
is_starred
:
# "a, *b = x" assigns a list to "b"
item_node
=
TypedExprNode
(
Builtin
.
list_type
,
may_be_none
=
False
,
pos
=
arg
.
pos
)
elif
rhs
is
self
.
object_expr
:
item_node
=
rhs
else
:
item_node
=
rhs
.
inferable_item_node
(
i
)
self
.
mark_assignment
(
arg
,
item_node
)
...
...
tests/run/type_inference.pyx
View file @
e7c7730c
...
...
@@ -287,6 +287,35 @@ def cascaded_assignment():
e
=
a
+
b
+
c
+
d
assert
typeof
(
e
)
==
"double"
def
unpacking
(
x
):
"""
>>> unpacking(0)
"""
a
,
b
,
c
,
d
=
x
,
1
,
2.0
,
[
3
]
assert
typeof
(
a
)
==
"Python object"
,
typeof
(
a
)
assert
typeof
(
b
)
==
"long"
,
typeof
(
b
)
assert
typeof
(
c
)
==
"double"
,
typeof
(
c
)
assert
typeof
(
d
)
==
"list object"
,
typeof
(
d
)
def
star_unpacking
(
*
x
):
"""
>>> star_unpacking(1, 2)
"""
a
,
b
=
x
c
,
*
d
=
x
*
e
,
f
=
x
*
g
,
g
=
x
# re-assignment
assert
typeof
(
a
)
==
"Python object"
,
typeof
(
a
)
assert
typeof
(
b
)
==
"Python object"
,
typeof
(
b
)
assert
typeof
(
c
)
==
"Python object"
,
typeof
(
c
)
assert
typeof
(
d
)
==
"list object"
,
typeof
(
d
)
assert
typeof
(
e
)
==
"list object"
,
typeof
(
e
)
assert
typeof
(
f
)
==
"Python object"
,
typeof
(
f
)
assert
typeof
(
g
)
==
"Python object"
,
typeof
(
f
)
def
increment
():
"""
>>> increment()
...
...
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