[New-bugs-announce] [issue19159] 2to3 incorrectly converts two parameter unicode() constructor to str()

Gregory P. Smith report at bugs.python.org
Fri Oct 4 02:57:01 CEST 2013


New submission from Gregory P. Smith:

>From a conversion through 2to3:

<       default_value=unicode("", "utf-8"),
---
>       default_value=str("", "utf-8"),

The Python 2 unicode constructor takes an optional second parameter which is the codec to use to convert when the first parameter is non-unicode.

2to3 should check the parameters on uses of unicode() and if there is a second parameter and the first is explicitly b"" bytes it should turn it into
  default_value=b"whatever".decode(second_param)

if the first is valid utf-8 and the second is "utf-8" (or its other spellings) it should leave it as is and simply become:
  default_value="thing passed to unicode() that was already utf-8"

----------
messages: 198929
nosy: gregory.p.smith
priority: normal
severity: normal
stage: needs patch
status: open
title: 2to3 incorrectly converts two parameter unicode() constructor to str()
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19159>
_______________________________________


More information about the New-bugs-announce mailing list