amyreese / fissix

backport of lib2to3, with enhancements
Other
45 stars 22 forks source link

fix: types.StringTypes replacement #46

Closed gaal-dev closed 1 month ago

gaal-dev commented 1 year ago

Hello.

The library provides only one type insted of two string types in Python 2 when replacing types.StringTypes. This results in incorrect behavior after applying the library.

Description

if isinstance(inputValue, types.StringTypes) and isinstance(outputValue, types.StringTypes):  # before
if isinstance(inputValue, (str,)) and isinstance(outputValue, (str,)):  # after

Fixes: #

if isinstance(inputValue, six.string_types) and isinstance(outputValue, six.string_types):

From the documentation: https://docs.python.org/2/library/types.html

types.StringTypes A sequence containing StringType and UnicodeType used to facilitate easier checking for any string object.

From the six library code: https://github.com/benjaminp/six/blob/master/six.py

In Python2, basestring is the base class of str and unicode types.

if PY3:
    string_types = str,
    ...
else:
    string_types = basestring
   ...

And it does not work properly in Python2 after changing original code

if isinstance(inputValue, (str,)) and isinstance(outputValue, (str,)):