Message350964
We are attempting to convert a large Python 2 code base. Following the guidance of the official documentation (https://docs.python.org/2/library/functions.html#basestring) we created tests in many, many places that look like this:
if isinstance(value, basestring):
if not isinstance(value, unicode):
value = value.decode(encoding)
else:
some other code
It seems that the 2to3 tool is unaware that replacing basestring with str in such cases will break the software.
Here's an example.
$ 2to3 repro.py
...
--- repro.py (original)
+++ repro.py (refactored)
@@ -1,8 +1,8 @@
from frobnitz import transform
def foo(value, encoding=None):
- if isinstance(value, basestring):
- if not isinstance(value, unicode):
+ if isinstance(value, str):
+ if not isinstance(value, str):
value = value.decode(encoding or "utf-8")
return value
else:
Help me understand how this "fix" results in the correct behavior. |
|
Date |
User |
Action |
Args |
2019-09-01 21:40:09 | bkline | set | recipients:
+ bkline |
2019-09-01 21:40:09 | bkline | set | messageid: <1567374009.32.0.247747586449.issue38003@roundup.psfhosted.org> |
2019-09-01 21:40:09 | bkline | link | issue38003 messages |
2019-09-01 21:40:09 | bkline | create | |
|