[issue34893] Add 2to3 fixer to change send and recv methods of socket object.

Pranav Devarakonda report at bugs.python.org
Sun Oct 7 14:10:04 EDT 2018


Pranav Devarakonda <devarakondapranav at 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 <report at bugs.python.org>
<https://bugs.python.org/issue34893>
_______________________________________


More information about the Python-bugs-list mailing list