If you give strlist.grow a subclass of str, strlist.grow will infinitely recurse.
This has come up because of changes using futurize.builtins.str made in an effort to make sourcecode compatible with python 2 and python 3.
It looks like the very strict type checks here are to blame:
|
if type(thing) == str_class: |
|
self.append(thing) |
|
|
|
# This will only ever match in Python 2 since str_class is str in |
|
# Python 3. |
|
elif type(thing) == str: |
|
self.append(unicode(thing)) # noqa: F821 undefined name 'unicode' |
In a pdb shell (running latest python 2.7) I get the following output:
(Pdb) ll
204 def grow(self, thing):
205 """Make the list longer, appending for unicode, extending otherwise."""
206 if type(thing) == str_class:
207 self.append(thing)
208
209 # This will only ever match in Python 2 since str_class is str in
210 # Python 3.
211 elif type(thing) == str:
212 self.append(unicode(thing)) # noqa: F821 undefined name 'unicode'
213
214 else:
215 # Recursively expand to a flat list; may deserve a C accelerator at
216 # some point.
217 for element in thing:
218 -> self.grow(element)
(Pdb) str
<type 'str'>
(Pdb) str_class
<type 'unicode'>
(Pdb) type(thing)
<class 'future.types.newstr.newstr'>
(Pdb) isinstance(thing, str)
False
(Pdb) isinstance(thing, str_class)
True
I suspect just changing the type(thing) == str_class lines to isinstance(type, str_class) will fix the issue.
If you give
strlist.growa subclass ofstr,strlist.growwill infinitely recurse.This has come up because of changes using
futurize.builtins.strmade in an effort to make sourcecode compatible with python 2 and python 3.It looks like the very strict type checks here are to blame:
pybars3/pybars/_compiler.py
Lines 191 to 197 in 7a8bd6d
In a pdb shell (running latest python 2.7) I get the following output:
I suspect just changing the
type(thing) == str_classlines toisinstance(type, str_class)will fix the issue.