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
7d8e5ed0
Commit
7d8e5ed0
authored
Oct 03, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent None assignments from disrupting safe type inference.
parent
6d2b5074
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
6 deletions
+29
-6
Cython/Compiler/TypeInference.py
Cython/Compiler/TypeInference.py
+20
-3
tests/run/type_inference.pyx
tests/run/type_inference.pyx
+9
-3
No files found.
Cython/Compiler/TypeInference.py
View file @
7d8e5ed0
...
...
@@ -415,6 +415,22 @@ class SimpleAssignmentTypeInferer(object):
entry
=
node
.
entry
return
spanning_type
(
types
,
entry
.
might_overflow
,
entry
.
pos
,
scope
)
def
inferred_types
(
entry
):
has_none
=
False
has_pyobjects
=
False
types
=
[]
for
assmt
in
entry
.
cf_assignments
:
if
assmt
.
rhs
.
is_none
:
has_none
=
True
else
:
rhs_type
=
assmt
.
inferred_type
if
rhs_type
and
rhs_type
.
is_pyobject
:
has_pyobjects
=
True
types
.
append
(
rhs_type
)
if
has_none
and
not
has_pyobjects
:
types
.
append
(
py_object_type
)
return
types
def
resolve_assignments
(
assignments
):
resolved
=
set
()
for
assmt
in
assignments
:
...
...
@@ -467,7 +483,7 @@ class SimpleAssignmentTypeInferer(object):
continue
entry_type
=
py_object_type
if
assmts_resolved
.
issuperset
(
entry
.
cf_assignments
):
types
=
[
assmt
.
inferred_type
for
assmt
in
entry
.
cf_assignments
]
types
=
inferred_types
(
entry
)
if
types
and
all
(
types
):
entry_type
=
spanning_type
(
types
,
entry
.
might_overflow
,
entry
.
pos
,
scope
)
...
...
@@ -477,8 +493,9 @@ class SimpleAssignmentTypeInferer(object):
def
reinfer
():
dirty
=
False
for
entry
in
inferred
:
types
=
[
assmt
.
infer_type
()
for
assmt
in
entry
.
cf_assignments
]
for
assmt
in
entry
.
cf_assignments
:
assmt
.
infer_type
()
types
=
inferred_types
(
entry
)
new_type
=
spanning_type
(
types
,
entry
.
might_overflow
,
entry
.
pos
,
scope
)
if
new_type
!=
entry
.
type
:
self
.
set_entry_type
(
entry
,
new_type
)
...
...
tests/run/type_inference.pyx
View file @
7d8e5ed0
...
...
@@ -137,15 +137,21 @@ def multiple_assignments():
a
=
3
a
=
4
a
=
5
assert
typeof
(
a
)
==
"long"
assert
typeof
(
a
)
==
"long"
,
typeof
(
a
)
b
=
a
b
=
3.1
b
=
3.14159
assert
typeof
(
b
)
==
"double"
assert
typeof
(
b
)
==
"double"
,
typeof
(
b
)
c
=
a
c
=
b
c
=
[
1
,
2
,
3
]
assert
typeof
(
c
)
==
"Python object"
assert
typeof
(
c
)
==
"Python object"
,
typeof
(
c
)
d
=
b'abc'
d
=
bytes
()
d
=
bytes
(
b'xyz'
)
d
=
None
assert
typeof
(
d
)
==
"bytes object"
,
typeof
(
d
)
def
arithmetic
():
"""
...
...
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