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
Boxiang Sun
cython
Commits
aae9d0c4
Commit
aae9d0c4
authored
Dec 04, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
type inference for SliceIndexNode
parent
0f9f7f1f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+9
-0
tests/run/type_inference.pyx
tests/run/type_inference.pyx
+21
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
aae9d0c4
...
...
@@ -2073,6 +2073,15 @@ class SliceIndexNode(ExprNode):
subexprs
=
[
'base'
,
'start'
,
'stop'
]
def
infer_type
(
self
,
env
):
base_type
=
self
.
base
.
infer_type
(
env
)
if
base_type
.
is_string
:
return
bytes_type
elif
base_type
in
(
bytes_type
,
str_type
,
unicode_type
,
list_type
,
tuple_type
):
return
base_type
return
py_object_type
def
calculate_constant_result
(
self
):
self
.
constant_result
=
self
.
base
.
constant_result
[
self
.
start
.
constant_result
:
self
.
stop
.
constant_result
]
...
...
tests/run/type_inference.pyx
View file @
aae9d0c4
...
...
@@ -46,6 +46,27 @@ def builtin_types():
B
=
bool
()
assert
typeof
(
B
)
==
"bool object"
,
typeof
(
B
)
def
slicing
():
"""
>>> slicing()
"""
b
=
b"abc"
assert
typeof
(
b
)
==
"char *"
,
typeof
(
b
)
b1
=
b
[
1
:
2
]
assert
typeof
(
b1
)
==
"bytes object"
,
typeof
(
b1
)
u
=
u"xyz"
assert
typeof
(
u
)
==
"unicode object"
,
typeof
(
u
)
u1
=
u
[
1
:
2
]
assert
typeof
(
u1
)
==
"unicode object"
,
typeof
(
u1
)
L
=
[
1
,
2
,
3
]
assert
typeof
(
L
)
==
"list object"
,
typeof
(
L
)
L1
=
L
[
1
:
2
]
assert
typeof
(
L1
)
==
"list object"
,
typeof
(
L1
)
t
=
(
4
,
5
,
6
)
assert
typeof
(
t
)
==
"tuple object"
,
typeof
(
t
)
t1
=
t
[
1
:
2
]
assert
typeof
(
t1
)
==
"tuple object"
,
typeof
(
t1
)
def
multiple_assignments
():
"""
>>> multiple_assignments()
...
...
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