[issue19543] Add -3 warnings for codec convenience method changes
Martin Panter
report at bugs.python.org
Sun Nov 10 11:35:40 CET 2013
Martin Panter added the comment:
Just thinking the first case might get quite a few false positives. Maybe that would still be acceptable, I dunno.
> - the str.encode method is called (redirect to codecs.encode to handle arbitrary input types in a forward compatible way)
I guess you are trying to catch cases like this, which I have come across quite a few times:
data.encode("hex") # data is a byte string
But I think you would also catch cases that depend on Python 2 “str” objects automatically converting to Unicode. Here are some examples taken from real code:
file_name.encode("utf-8") # File name parameter may be str or unicode
# Code meant to be compatible with both Python 2 and 3:
"""<?xml . . . encoding="iso-8859-1"?>""".encode("iso-8859-1")
("data %s\n" % len(...)).encode("ascii")
----------
nosy: +vadmium
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19543>
_______________________________________
More information about the Python-bugs-list
mailing list