Pranav Devarakonda <devarakondapra...@yahoo.com> added the comment:

> One possibility is to add a type check to the generated code, "send(x)" -> 
> send(x.encode() if type(x)==bytes else x)"

That would have solved the problem. However we cannot check the type of the 
object while the parsing is going on. For example, printing out the type(x) for 
the above example in any of the fixers would print "lib2to3.pytree.Node" (or 
"lib2to3.pytree.Leaf" depending on the object) but not the expected type() of 
the object like str or bytes.

I haven't found out any method that can actually find out the type of the 
object in the fixer. If that can be done, then writing the fixer is pretty much 
straight forward. 

The other fixers in lib2to3, for example fix_dict.py, would convert all 
instances of viewkeys() to keys() irrespective of the type of the object that 
has called the method. That is also the case with all other fixers as well. 
Would appreciate very much if somebody can suggest how to do this.

But since that is not the case, the fixer code has to handle these cases 
individually and I expect the current fixer to do a good job for the same.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34893>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to