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
52e6c71b
Commit
52e6c71b
authored
Oct 10, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
disable coercion from str->bytes, fix coercion from str->object
parent
852feeb7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
26 deletions
+37
-26
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-5
tests/errors/string_assignments.pyx
tests/errors/string_assignments.pyx
+31
-21
No files found.
Cython/Compiler/ExprNodes.py
View file @
52e6c71b
...
...
@@ -909,12 +909,13 @@ class StringNode(PyConstNode):
def
coerce_to
(
self
,
dst_type
,
env
):
if
dst_type
is
Builtin
.
str_type
:
return
self
if
dst_type
is
Builtin
.
bytes_type
:
# special case: bytes = 'str literal'
return
BytesNode
(
self
.
pos
,
value
=
self
.
value
)
el
if
not
dst_type
.
is_pyobject
:
#
if dst_type is Builtin.bytes_type:
#
# special case: bytes = 'str literal'
#
return BytesNode(self.pos, value=self.value)
if
not
dst_type
.
is_pyobject
:
return
BytesNode
(
self
.
pos
,
value
=
self
.
value
).
coerce_to
(
dst_type
,
env
)
self
.
check_for_coercion_error
(
dst_type
)
if
dst_type
is
not
py_object_type
:
self
.
check_for_coercion_error
(
dst_type
,
fail
=
True
)
return
self
def
generate_evaluation_code
(
self
,
code
):
...
...
tests/errors/string_assignments.pyx
View file @
52e6c71b
...
...
@@ -2,15 +2,14 @@
# ok:
cdef
char
*
c1
=
"abc"
cdef
bytes
b1
=
"abc"
cdef
str
s1
=
"abc"
cdef
unicode
u1
=
u"abc"
cdef
bytes
b
2
=
b"abc"
cdef
bytes
b
1
=
b"abc"
cdef
char
*
c2
=
b"abc"
cdef
bytes
b
3
=
c1
cdef
bytes
b
2
=
c1
cdef
char
*
c3
=
b1
cdef
object
o1
=
"abc"
...
...
@@ -42,24 +41,35 @@ cdef unicode u_f3 = b"abc"
cdef
unicode
u_f4
=
b1
cdef
unicode
u_f5
=
c1
cdef
tuple
t_f1
=
"abc"
cdef
tuple
t_f2
=
u"abc"
cdef
tuple
t_f3
=
b"abc"
cdef
list
l_f1
=
s1
cdef
list
l_f2
=
b1
cdef
list
l_f3
=
u1
_ERRORS
=
u"""
26:20: Unicode objects do not support coercion to C types.
27:22: Unicode objects do not support coercion to C types.
28:22: 'str' objects do not support coercion to C types.
30:20: Cannot convert Unicode string to 'bytes' implicitly, encoding required.
31:22: Cannot convert Unicode string to 'bytes' implicitly, encoding required.
32:22: Cannot convert 'str' to 'bytes' implicitly. This is not portable.
34:17: Cannot assign type 'char *' to 'str object'
35:19: Cannot convert 'bytes' object to str implicitly. This is not portable to Py3.
36:17: Cannot convert Unicode string to 'str' implicitly. This is not portable and requires explicit encoding.
37:19: Cannot convert Unicode string to 'str' implicitly. This is not portable and requires explicit encoding.
39:20: str objects do not support coercion to unicode, use a unicode string literal instead (u'')
40:22: str objects do not support coercion to unicode, use a unicode string literal instead (u'')
41:20: Cannot assign type 'char *' to 'unicode object'
42:22: Cannot convert 'bytes' object to unicode implicitly, decoding required
43:22: Cannot convert 'char*' to unicode implicitly, decoding required
25:20: Unicode objects do not support coercion to C types.
26:22: Unicode objects do not support coercion to C types.
27:22: 'str' objects do not support coercion to C types.
29:20: Cannot convert Unicode string to 'bytes' implicitly, encoding required.
30:22: Cannot convert Unicode string to 'bytes' implicitly, encoding required.
31:22: Cannot convert 'str' to 'bytes' implicitly. This is not portable.
33:17: Cannot assign type 'char *' to 'str object'
34:19: Cannot convert 'bytes' object to str implicitly. This is not portable to Py3.
35:17: Cannot convert Unicode string to 'str' implicitly. This is not portable and requires explicit encoding.
36:19: Cannot convert Unicode string to 'str' implicitly. This is not portable and requires explicit encoding.
38:20: str objects do not support coercion to unicode, use a unicode string literal instead (u'')
39:22: str objects do not support coercion to unicode, use a unicode string literal instead (u'')
40:20: Cannot assign type 'char *' to 'unicode object'
41:22: Cannot convert 'bytes' object to unicode implicitly, decoding required
42:22: Cannot convert 'char*' to unicode implicitly, decoding required
44:19: Cannot assign type 'str object' to 'tuple object'
45:18: Cannot assign type 'unicode object' to 'tuple object'
46:18: Cannot assign type 'char *' to 'tuple object'
"""
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