This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bkline
Recipients bkline
Date 2019-09-01.21:40:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1567374009.32.0.247747586449.issue38003@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-09-01 21:40:09bklinesetrecipients: + bkline
2019-09-01 21:40:09bklinesetmessageid: <1567374009.32.0.247747586449.issue38003@roundup.psfhosted.org>
2019-09-01 21:40:09bklinelinkissue38003 messages
2019-09-01 21:40:09bklinecreate