Issue 17823: 2to3 fixers for missing codecs (original) (raw)

Created on 2013-04-23 18:11 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue17823_lib2to3_fixer_for_binary_codecs.diff ncoghlan,2013-11-06 14:06 Proof of concept that just implements the "encode" case review
Messages (10)
msg187662 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-04-23 18:11
Quoting Victor Stinner from : """ It's maybe possible for write some 2to3 fixers for the following examples: "...".encode("base64") => base64.b64encode("...") "...".encode("rot13") => do nothing (but display a warning?) "...".encode("zlib") => zlib.compress("...") "...".encode("hex") => base64.b16encode("...") "...".encode("bz2") => bz2.compress("...") "...".decode("base64") => base64.b64decode("...") "...".decode("rot13") => do nothing (but display a warning?) "...".decode("zlib") => zlib.decompress("...") "...".decode("hex") => base64.b16decode("...") "...".decode("bz2") => bz2.decompress("...") """ Unfortunately I don't know where is the syntax for writing fixers.
msg187766 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2013-04-25 08:14
A more consistent alternative conversion: "...".encode("base64") => codecs.encode("...", "base64_codec") "...".encode("rot13") => codecs.encode("...", "rot_13") "...".encode("zlib") => codecs.encode("...", "zlib_codec") "...".encode("hex") => codecs.encode("...", "hex_codec") "...".encode("bz2") => codecs.encode("...", "bz2_codec") "...".decode("base64") => codecs.decode("...", "base64_codec") "...".decode("rot13") => codecs.decode("...", "rot_13") "...".decode("zlib") => codecs.decode("...", "zlib_codec") "...".decode("hex") => codecs.decode("...", "hex_codec") "...".decode("bz2") => codecs.decode("...", "bz2_codec")
msg187767 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2013-04-25 08:18
On 25.04.2013 10:14, Nick Coghlan wrote: > > Nick Coghlan added the comment: > > A more consistent alternative conversion: > > "...".encode("base64") => codecs.encode("...", "base64_codec") > "...".encode("rot13") => codecs.encode("...", "rot_13") > "...".encode("zlib") => codecs.encode("...", "zlib_codec") > "...".encode("hex") => codecs.encode("...", "hex_codec") > "...".encode("bz2") => codecs.encode("...", "bz2_codec") > > "...".decode("base64") => codecs.decode("...", "base64_codec") > "...".decode("rot13") => codecs.decode("...", "rot_13") > "...".decode("zlib") => codecs.decode("...", "zlib_codec") > "...".decode("hex") => codecs.decode("...", "hex_codec") > "...".decode("bz2") => codecs.decode("...", "bz2_codec") It would be better to add back the aliases we had for these codecs.
msg187768 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2013-04-25 08:28
Sure, that's what issue 7475 is about, and if we do that, then the fixers can be simplified to just replace the method with the function call for the known set of non-text-model related codecs. However, I also wanted to make a note of what the fixers should look like for a version of the fixer that can provide compatibility with 3.2+ rather than relying on the aliases being restored in 3.4
msg187772 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-04-25 11:00
> A more consistent alternative conversion: What advantages `codecs.encode("...", "base64_codec")` has comparing with `base64.b64encode("...")`? The latter is at least more portable and powerfull (it allows to specify altchars). I think that main problem with issue 7475 is that people don't think about a different (actually the most obvious) way to do base64 encoding.
msg202263 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2013-11-06 12:40
Switch direction of dependency to make this fixer rely on restoring the codec aliases in issue 7475 first.
msg202266 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2013-11-06 14:06
Attached diff shows a proof of concept fixer for the encode case. It could be adjusted fairly easily to also handle decode methods (by including an alternative in the pattern and also capturing the method name) I'm sure how useful such a fixer would be in practice, though, since it only triggers when the codec name is passed as a literal - passing in a variable instead keeps it from firing.
msg202267 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2013-11-06 14:18
On 7 November 2013 00:06, Nick Coghlan <report@bugs.python.org> wrote: > I'm sure how useful such a fixer would be in practice, though, since it only triggers when the codec name is passed as a literal - passing in a variable instead keeps it from firing. Oops, that should say "I'm *not* sure" :)
msg202328 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2013-11-07 12:23
After thinking about this some more, perhaps a -3 warning in 2.7 would be a better solution? That would be more robust, as it could complain any time unicode.encode produced unicode and str.decode produced str and point users to the codecs module level functions as a forward compatible alternative. Producing Py3k warnings when calling unicode.decode and str.encode under -3 would also be appropriate (although those warnings may already exist).
msg202514 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2013-11-10 09:22
Due to the data driven nature of this particular incompatibility, I'm rejecting this in favour of the Py3k warning based approach in issue 19543.
History
Date User Action Args
2022-04-11 14:57:44 admin set github: 62023
2013-11-10 09:22:10 ncoghlan set status: open -> closedmessages: + dependencies: - codecs missing: base64 bz2 hex zlib hex_codec ...resolution: rejectedstage: resolved
2013-11-08 05:24:57 martin.panter set nosy: + martin.panter
2013-11-07 12:37:06 ezio.melotti set nosy: + ezio.melotti
2013-11-07 12:23:12 ncoghlan set messages: +
2013-11-06 15:17:28 meador.inge set nosy: + meador.inge
2013-11-06 14🔞45 ncoghlan set messages: +
2013-11-06 14:06:21 ncoghlan set files: + issue17823_lib2to3_fixer_for_binary_codecs.diffkeywords: + patchmessages: +
2013-11-06 12:41:41 ncoghlan unlink issue7475 dependencies
2013-11-06 12:40:42 ncoghlan set dependencies: + codecs missing: base64 bz2 hex zlib hex_codec ...messages: +
2013-11-06 12:23:43 ncoghlan set assignee: ncoghlan
2013-04-25 11:00:00 serhiy.storchaka set messages: +
2013-04-25 08:28:01 ncoghlan set messages: +
2013-04-25 08🔞04 lemburg set nosy: + lemburgmessages: +
2013-04-25 08:14:29 ncoghlan set nosy: + ncoghlanmessages: +
2013-04-25 07:53:34 serhiy.storchaka link issue7475 dependencies
2013-04-23 18:13:33 serhiy.storchaka set title: 2to3 fixers for -> 2to3 fixers for missing codecs
2013-04-23 18:12:25 serhiy.storchaka set nosy: + vstinner
2013-04-23 18:11:54 serhiy.storchaka create