[New-bugs-announce] [issue38003] Incorrect "fixing" of isinstance tests for basestring
Bob Kline
report at bugs.python.org
Sun Sep 1 17:40:09 EDT 2019
New submission from Bob Kline <bkline at rksystems.com>:
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.
----------
components: 2to3 (2.x to 3.x conversion tool)
messages: 350964
nosy: bkline
priority: normal
severity: normal
status: open
title: Incorrect "fixing" of isinstance tests for basestring
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38003>
_______________________________________
More information about the New-bugs-announce
mailing list