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
6d3aa1bd
Commit
6d3aa1bd
authored
May 15, 2010
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
8737e4ac
850c831d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
2 deletions
+45
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+5
-2
tests/run/type_inference.pyx
tests/run/type_inference.pyx
+40
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
6d3aa1bd
...
...
@@ -1892,12 +1892,12 @@ class IndexNode(ExprNode):
return
self
.
base
.
type_dependencies
(
env
)
def
infer_type
(
self
,
env
):
if
isinstance
(
self
.
base
,
StringNode
):
# FIXME: BytesNode?
if
isinstance
(
self
.
base
,
BytesNode
):
return
py_object_type
base_type
=
self
.
base
.
infer_type
(
env
)
if
base_type
.
is_ptr
or
base_type
.
is_array
:
return
base_type
.
base_type
elif
base_type
is
Builtin
.
unicode_type
and
self
.
index
.
infer_type
(
env
).
is_int
:
elif
base_type
is
unicode_type
and
self
.
index
.
infer_type
(
env
).
is_int
:
# Py_UNICODE will automatically coerce to a unicode string
# if required, so this is safe. We only infer Py_UNICODE
# when the index is a C integer type. Otherwise, we may
...
...
@@ -1906,6 +1906,9 @@ class IndexNode(ExprNode):
# to receive it, throw it away, and potentially rebuild it
# on a subsequent PyObject coercion.
return
PyrexTypes
.
c_py_unicode_type
elif
base_type
in
(
str_type
,
unicode_type
):
# these types will always return themselves on Python indexing
return
base_type
else
:
# TODO: Handle buffers (hopefully without too much redundancy).
return
py_object_type
...
...
tests/run/type_inference.pyx
View file @
6d3aa1bd
...
...
@@ -71,6 +71,27 @@ def slicing():
t1
=
t
[
1
:
2
]
assert
typeof
(
t1
)
==
"tuple object"
,
typeof
(
t1
)
def
indexing
():
"""
>>> indexing()
"""
b
=
b"abc"
assert
typeof
(
b
)
==
"char *"
,
typeof
(
b
)
b1
=
b
[
1
]
assert
typeof
(
b1
)
==
"char"
,
typeof
(
b1
)
# FIXME: bytes object ??
u
=
u"xyz"
assert
typeof
(
u
)
==
"unicode object"
,
typeof
(
u
)
u1
=
u
[
1
]
assert
typeof
(
u1
)
==
"Py_UNICODE"
,
typeof
(
u1
)
L
=
[
1
,
2
,
3
]
assert
typeof
(
L
)
==
"list object"
,
typeof
(
L
)
L1
=
L
[
1
]
assert
typeof
(
L1
)
==
"Python object"
,
typeof
(
L1
)
t
=
(
4
,
5
,
6
)
assert
typeof
(
t
)
==
"tuple object"
,
typeof
(
t
)
t1
=
t
[
1
]
assert
typeof
(
t1
)
==
"Python object"
,
typeof
(
t1
)
def
multiple_assignments
():
"""
>>> multiple_assignments()
...
...
@@ -197,6 +218,15 @@ def loop_over_charptr():
pass
return
typeof
(
c
)
def
loop_over_bytes_literal
():
"""
>>> print( loop_over_bytes_literal() )
Python object
"""
for
c
in
b'abcdefg'
:
pass
return
typeof
(
c
)
def
loop_over_bytes
():
"""
>>> print( loop_over_bytes() )
...
...
@@ -207,6 +237,16 @@ def loop_over_bytes():
pass
return
typeof
(
c
)
def
loop_over_str
():
"""
>>> print( loop_over_str() )
str object
"""
cdef
str
string
=
'abcdefg'
for
c
in
string
:
pass
return
typeof
(
c
)
def
loop_over_unicode
():
"""
>>> print( loop_over_unicode() )
...
...
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