Re: OT: Python 3 conversion
Matthias Andree <[email protected]> Wed, 27 Oct 2021 22:31:12 +0200
| Newsgroups | gmane.mail.getmail.user |
|---|---|
| Message-ID | <[email protected]> |
Am 27.10.21 um 21:34 schrieb Charles Cazabon: > Matthias Andree <[email protected]> wrote: >> The string vs. bytes vs. Unicode matter is still needed, so reviewing >> and checking if you need .decode() or .encode(), or class/exception >> updates are required > Yes, this is a big part of it. Just arbitrarily throwing away the "u" prefix > on string literals and changing to bytes where the prefix wasn't used doesn't > get you very far. It requires knowledge of the codebase and what it's doing. > >> , and sometimes I found it necessary to convert some method outputs to >> list()s explicitly ("for i in list(former_result):") > I'm glad I'm not the only one who finds this change in Python 3 a bit > annoying. I did not call it annoying, but it is something to watch out for. There are various solutions to this change, some more and some less Python-idiomatic, and I am not claiming the list() creation from the view was particularly smart, but it was an obvious change that didn't require a lot of thinking for a quick conversion job. https://docs.python.org/3/whatsnew/3.0.html#views-and-iterators-instead-of-lists > A barebones conversion is doable, but it gets worse as the codebase grows > larger or more complex. For getmail, it's a significant chunk of work that I > think is better invested in a rewrite that cleans up a ton of stuff from early > Python 2, and even Python 1.5, that I had to monkeypatch in or implement > myself because it simply didn't exist in the ecosystem at the time. It's just that rewrites tend to lose workarounds at application level, too. Perhaps that's desirable if the situation to work around is extinct, but indeed recent and idiomatic Python 3.x code looks quite different from what we used to write when we learned Python 1.5 :-)