Re:Mercurial’s journey to and reflections on Python 3
by quietbritishjim on Monday January 13, 2020 @04:47PM
(#22039056)
Surely any "natural" string would be better represented as unicode in Python 2? What is an example that wouldn't be?
[ Parent
| on HN ]
Re:Mercurial’s journey to and reflections on Python 3
by masklinn on Tuesday January 14, 2020 @01:28AM
(#22042375)
> Surely any "natural" string would be better represented as unicode in Python 2?
No because much of the stdlib works in terms of native strings and will choke (or worse silently fuck up) on the other. Yes also in python 2, the stdlib was absolutely not “unicode clean”.
So a transitional / polyglot codebase has and needs not 2 but 3 string types: bytes, unicode, and native. And neither “unicode literals” nor “bytes literals” were good things to apply across the board.
Re:Mercurial’s journey to and reflections on Python 3
by cjbillington on Tuesday January 14, 2020 @02:34AM
(#22042660)
I've found myself defining `native_str = bytes if PY2 else str` (with `if PY2: str = unicode` at the top of the file, as in all my py2/py3 polyglot code) because there are some things that need bytes on Python 2 and unicode on Python 3 - e.g. the `__file__` attribute of a dynamically created module or other low-level things.
Re:Mercurial’s journey to and reflections on Python 3
by war1025 on Monday January 13, 2020 @05:39PM
(#22039541)
I believe what they meant was that for many strings it really shouldn't matter if they were bytes or unicode. They would perform their function correctly either way. That's completely true, but you do still have to go through and find the cases where that doesn't work.