Commit 4571ec70 authored by Stefan Behnel's avatar Stefan Behnel

disallow assignment from bytes to basestring (only allow str/unicode)

parent 94f7b0eb
...@@ -1160,7 +1160,7 @@ class BytesNode(ConstNode): ...@@ -1160,7 +1160,7 @@ class BytesNode(ConstNode):
node = BytesNode(self.pos, value=self.value, node = BytesNode(self.pos, value=self.value,
constant_result=self.constant_result) constant_result=self.constant_result)
if dst_type.is_pyobject: 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 node.type = Builtin.bytes_type
else: else:
self.check_for_coercion_error(dst_type, env, fail=True) self.check_for_coercion_error(dst_type, env, fail=True)
......
...@@ -963,7 +963,7 @@ class BuiltinObjectType(PyObjectType): ...@@ -963,7 +963,7 @@ class BuiltinObjectType(PyObjectType):
def assignable_from(self, src_type): def assignable_from(self, src_type):
if isinstance(src_type, BuiltinObjectType): if isinstance(src_type, BuiltinObjectType):
if self.name == 'basestring': if self.name == 'basestring':
return src_type.name in ('bytes', 'str', 'unicode', 'basestring') return src_type.name in ('str', 'unicode', 'basestring')
else: else:
return src_type.name == self.name return src_type.name == self.name
elif src_type.is_extension_type: elif src_type.is_extension_type:
......
...@@ -60,8 +60,6 @@ def basestring_typed_variable(obj): ...@@ -60,8 +60,6 @@ def basestring_typed_variable(obj):
assert s assert s
s = 'abc' s = 'abc'
assert s assert s
s = b'abc'
assert s
# make sure coercion also works in conditional expressions # make sure coercion also works in conditional expressions
s = u'abc' if obj else b'abc' if obj else 'abc' s = u'abc' if obj else b'abc' if obj else 'abc'
assert s assert s
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment