From 4571ec7078ced5cc6990ebc8517bcf604bac7468 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 6 Oct 2013 12:23:35 +0200 Subject: [PATCH] disallow assignment from bytes to basestring (only allow str/unicode) --- Cython/Compiler/ExprNodes.py | 2 +- Cython/Compiler/PyrexTypes.py | 2 +- tests/run/builtin_basestring.pyx | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 25f2bca..1bd1ed8 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1160,7 +1160,7 @@ class BytesNode(ConstNode): node = BytesNode(self.pos, value=self.value, constant_result=self.constant_result) if dst_type.is_pyobject: - if dst_type in (py_object_type, Builtin.bytes_type, Builtin.basestring_type): + if dst_type in (py_object_type, Builtin.bytes_type): node.type = Builtin.bytes_type else: self.check_for_coercion_error(dst_type, env, fail=True) diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 18eda50..d6429f0 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -963,7 +963,7 @@ class BuiltinObjectType(PyObjectType): def assignable_from(self, src_type): if isinstance(src_type, BuiltinObjectType): if self.name == 'basestring': - return src_type.name in ('bytes', 'str', 'unicode', 'basestring') + return src_type.name in ('str', 'unicode', 'basestring') else: return src_type.name == self.name elif src_type.is_extension_type: diff --git a/tests/run/builtin_basestring.pyx b/tests/run/builtin_basestring.pyx index 0a811ea..018d23e 100644 --- a/tests/run/builtin_basestring.pyx +++ b/tests/run/builtin_basestring.pyx @@ -60,8 +60,6 @@ def basestring_typed_variable(obj): assert s s = 'abc' assert s - s = b'abc' - assert s # make sure coercion also works in conditional expressions s = u'abc' if obj else b'abc' if obj else 'abc' assert s -- 2.7.4