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 devarakondapranav
Recipients benjamin.peterson, devarakondapranav, rhettinger, serhiy.storchaka, xtreak
Date 2018-10-07.18:10:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538935804.14.0.545547206417.issue34893@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2018-10-07 18:10:04devarakondapranavsetrecipients: + devarakondapranav, rhettinger, benjamin.peterson, serhiy.storchaka, xtreak
2018-10-07 18:10:04devarakondapranavsetmessageid: <1538935804.14.0.545547206417.issue34893@psf.upfronthosting.co.za>
2018-10-07 18:10:04devarakondapranavlinkissue34893 messages
2018-10-07 18:10:04devarakondapranavcreate