Pranav Devarakonda added the comment:
Thank you very much for pointing out some helpful things, Karthikeyan.
>True if 1 in list(a.keys()) if type(a) == dict else a.keys() else False
True that the fixer would return a syntax error in this case. I missed adding a
pair of parenthesis to
New submission from Pranav Devarakonda :
fix_dict.py applies fixes to every instance of keys(), items() or values()
irrespective of the type of object. Since 2to3 cannot check the type of the
object, we can at least add the check to the generated code like...
d.keys() -> list(d.keys) if t
Pranav Devarakonda added the comment:
I have added a final condition that converts the arguments passed to bytes only
if the type of object is socket and the method is send() in the generated code.
All the other conversions still function as expected.
--
Added file: https
Pranav Devarakonda added the comment:
I am sorry. I got you completely wrong with this > "One possibility is to add a
type check to the generated code"
I thought you were asking to check the type in the fixer itself.
I get it now. So you meant to add the type check for the cha
Pranav Devarakonda 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
Pranav Devarakonda added the comment:
Thanks for pointing out these cases. I kept in mind the Python 2 documentation
which says socket.send method expects a string and hence made that fixer. I
have tweaked that fixer to handle the pointed cases and a few additional ones
too. Please find
Pranav Devarakonda added the comment:
Thanks Karthikeyan
--
___
Python tracker
<https://bugs.python.org/issue34893>
___
___
Python-bugs-list mailing list
Unsub
Pranav Devarakonda added the comment:
Thanks for taking time and updating this, Karthikeyan Singaravelan. I do agree
that there there is no proper way to find out if an object is of type socket or
not.
However other fixers in lib2to3 are not any different. For example the
fix_dict.py
New submission from Pranav Devarakonda :
The send() method of the the Socket object in Python 3.x requires the data to
be sent to be first converted into bytes(object) which was not the case with
Python 2.x. The 2to3 tool doesn't handle this case and hence an explicit fixer
would help