Live data from Hacker News

Numpy: Plan for dropping Python 2.7 support

github.com

381–390 of 390 posts

Re: Numpy: Plan for dropping Python 2.7 support

#381
post #285

Earlier quoted context omitted.

Locales are not a real way of specifying an encoding for standard in and out. They were not designed for a world with Unicode and UTF-8 in it; they were designed for a world with limited character sets where your text data would probably not be sent outside of your country. Here are some reasons not to try to get your locale to tell you about UTF-8: - There is no standard for this. - Locale suffixes ".utf8" and ".UTF…

> Locale suffixes ".utf8" and ".UTF-8" are hacks by specific Linux distributions, and people want their Python code to work even if their system has not implemented this hack. I do want my Python code to work, yes. But I assure you that if my locale says ru_RU.KOI8-R, when I say "work", I don't mean "dump garbled stuff on my screen, because you output UTF-8 when I specifically asked you to use KOI8-R". I also don't s…

> Locales are a generic mechanism for dealing with encodings. What makes UTF-8 special in that regard, and why is an UTF-8 locale a hack?

Locales are a generic mechanism for dealing with code that should run differently in different countries. There have been other HN discussions recently about why this is terrible in the present day. Encodings are just one aspect of that.

The whole thing where you name a locale, then put a dot and tell it what encoding you really wanted, is what I'm referring to as a hack. There is no standard for locales with dots in them. But the locale system was created at a time when, say, the US was using ISO-8859-1 and Poland was using ISO-8859-2, and this was just a fact about how you had to deal with text.

But that's exactly what Unicode got rid of! You don't make Unicode decisions by country (with terribly awkward exceptions such as Japan, where Unicode itself is unpopular, and Python is too). It's not like the US uses UTF-8 and Canada uses UTF-16. You make Unicode decisions based on the OS and APIs that you're interacting with. And that's why we have this Linux dot convention for overriding what the locale would otherwise say so we can use Unicode.

So your recommendation to use locales is actually a recommendation to mostly ignore locales, and just use the part after the dot as the name of the encoding you should be using. And to make wild-ass wrong guesses if there's no dot. Taking the locale "C" and interpreting it as the encoding "ASCII" is an example of a wild-ass wrong guess.

But there are already environment variables that configure Python to use a particular encoding, without hacking it on top of archaic shit like locales.

And harm is done by trying to infer the encoding from the locale, because of the complete wrongness of assuming the "C" locale means to use Python's "ASCII" encoding. The resulting behavior is not correct, and the reasoning for it is not correct. It's a bug. It will probably be fixed in one of the next two versions of Python.

People run Python from cron jobs, from IDEs, from all sorts of places that don't set the locale the way the Ubuntu shell does, and get bafflingly inconsistent results. You can say "fix your locales then" all you want, but this is not an answer that makes Python more usable, and the developers have acknowledged this.

Here's a particular example of where I think you're coming at this from the wrong direction, where I think you're taking the current behavior of Python as if it were actually some sort of intentionally-designed standard:

> That's true for any locale, if a character comes up in the output that cannot be encoded in it - it should just use some reasonable substitution. And if you're actually dealing with binary data, then you should be reading and writing bytes objects, not printing strings, and then the whole question of encoding is moot.

You don't encode things in a locale! You encode things in encodings! I'm definitely not talking about binary data, I'm talking about printing out perfectly normal characters like "ü".

The locale "C" does not tell you anything about what encoding to use. Which is very different from Python's current assumption (which may go away in 3.7) that it's telling you to use ASCII and explode.

Re: Numpy: Plan for dropping Python 2.7 support

#382
post #225

Earlier quoted context omitted.

Wild speculation (I'm relatively new to Python), it might also have to do with the Python community having several personalities. Python 3 solves a lot of problems for me, as someone who does a lot of NLP work, and generally has to deal with strings from the outside world and multiple languages and all that on a more-or-less constant basis. I imagine it solves some problems for Web developers, too, though possibly to…

Agreed. My background is also in NLP and I made the switch to Python 3 early and enthusiastically because it resolved a lot of issues around working with multilingual text.

Same here!

Re: Numpy: Plan for dropping Python 2.7 support

#383
post #381

Earlier quoted context omitted.

> Locale suffixes ".utf8" and ".UTF-8" are hacks by specific Linux distributions, and people want their Python code to work even if their system has not implemented this hack. I do want my Python code to work, yes. But I assure you that if my locale says ru_RU.KOI8-R, when I say "work", I don't mean "dump garbled stuff on my screen, because you output UTF-8 when I specifically asked you to use KOI8-R". I also don't s…

> Locales are a generic mechanism for dealing with encodings. What makes UTF-8 special in that regard, and why is an UTF-8 locale a hack? Locales are a generic mechanism for dealing with code that should run differently in different countries. There have been other HN discussions recently about why this is terrible in the present day. Encodings are just one aspect of that. The whole thing where you name a locale, the…

This really has nothing to do with Python per se. Python should do the exact same thing that C does, which is to say, what mbstowcs and wcstombs do. And those do "infer" encoding from locale.

I agree that the conflation of encodings and locales in Unix is rather unfortunate, but, again - nothing to do with Python. On Unix, Python should do what well-behaved Unix apps do, for the sake of consistency and interoperability.

Re: Numpy: Plan for dropping Python 2.7 support

#384

Earlier quoted context omitted.

You don't need to do any of that. If you use `input()`, you get a string - all conversions are done for you. If you're reading from a file (or from stdin, treating it as a file object), again, in text mode you just get strings. Same thing for printing - if you print strings, they will get converted to the encoding appropriate for the target terminal. So, what is it exactly that you're trying to do?

IRC logs with IRC control code characters in them don't work nicely with python 3 text strings, for example.

Why not? There's no restriction on what kinds of characters can appear inside a Python Unicode string.

Or do you mean that the text in the log is UTF-8, but the log itself as a whole is not, because those control characters are mixed into it in (effectively) a different encoding? Then the log isn't a single string, and shouldn't be treated as such.

Re: Numpy: Plan for dropping Python 2.7 support

#385

Earlier quoted context omitted.

Nonsense. Use six, use tox for testing in both, easy peasy. They're not that different. Plenty of libraries do it. No reason scripts can't too. Plenty do. Specify a "/usr/bin/env python3" shebang if you want to use any cool features like f-strings

Thank you, I appreciate the reply, but taking a bunch of dependencies is not reasaonable. It is as if you said "Does your shell script use associative arrays? Just install bash 4 on your users machines..." tox apparently depends on virtualenv; this is reasonable if your software is primarily Python, but absurd if your package merely uses Python for one-off scripts. macOS doesn't even install pip by default. I guess w…

Using virtualenv for development doesn't mean your users have to install it. The Python website has some pages on supporting both major versions.[1][2]

[1] https://wiki.python.org/moin/PortingToPy3k/BilingualQuickRef

[2] https://docs.python.org/3/howto/pyporting.html

Re: Numpy: Plan for dropping Python 2.7 support

#386
post #373

Earlier quoted context omitted.

Multi-line lambdas will never happen. Lambdas are expressions. "Multi-line" means statements. There is no sane way you could embed statements into an expression with whitespace-based block syntax.

Fine, not technically lambdas, but still: function bodies declared inline in function calls. This provides great flexibility in higher-order functions. > There is no sane way you could embed statements into an expression with whitespace-based block syntax. Ruby does it. Of course, Ruby has a limitation that a function call may only have one "block", but still - Ruby blocks are statements embedded into an expression i…

Ruby has explicit syntax to end groups of statements. Python is equally powerful when it comes to higher-order functions; it just enforces a flatter, more explicit style.

Re: Numpy: Plan for dropping Python 2.7 support

#387
post #320

Earlier quoted context omitted.

This is an ancient argument because no one can convince you that you need 3 for your use case. All I can do is say why I like it, and list reasons that probably don't apply to you or you would have switched already. For example, print and division made more sense to me in 3, judging from friends who taught 2 and said those were always sticky for some students in every class. Intuitive lowers the barrier to entry. (Bu…

The project failed because print was not a function, is not something one hears often.

Unless the project is teaching students python.

EDIT: More seriously py2's print handles parens in unpredictable ways if you have open questions about types, which has been a nightmare for me on multiple occasions.

I trust you that you never encountered them, but I did.

The whole point of my original post was begging for people to realize their personal experiences aren't universal. The py3 changes solve something for us, help us read code and avoid bugs, it's not just a novelty fetish, I promise. Unfortunately you only have our word for it...

Re: Numpy: Plan for dropping Python 2.7 support

#388
post #362

Earlier quoted context omitted.

There are some great things about Python 3, and then there are some things that are more subjective. But we have to ask at what cost? Breaking compatibility has required developers to spend huge amounts of time porting and worrying about compatibility that they could have spent on other things. Many of the best features of Python 3 could be introduced in a backwards compatible way. Further, the language itself could…

Er, maybe you never heard of Stackless Python (micro-threads) or PyPy (JIT)?

Of course I have, they were what I was referring to. If we didn't have to deal with this python 2/3 schism, there's a solid chance they'd be part of mainline python by now.

Re: Numpy: Plan for dropping Python 2.7 support

#389

Earlier quoted context omitted.

The double underscore methods are some of the ugliest parts of Python. If they were going to break compatibility, I'd get rid of them too.

I think you're right, only this wouldn't require breaking compatibility. It doesn't even require a python upgrade, you could just make a base class that remaps nicer named functions to the standard ones, like baseclass.is_lower_than = baseclass.__lt__

You're probably right. Sadly, the vast majority of the python upgrades probably did not require breaking compatibility. Or if they did, they weren't worth it. I understand that iterators are arguably better than lists and print should arguably be a real function, but those advantages are far too small to justify breaking compatibility.

Re: Numpy: Plan for dropping Python 2.7 support

#390
post #43
post #10

Good. The glacial migration from Python 2 to 3 is one of the worst things about an otherwise fantastic ecosystem. The tide is turning though, with Django having already dropped support for 2, and now with Numpy too hopefully Python 2 can be properly consigned to the history books. For people wondering why it's been like this for almost a decade(!) since Python 3.0 was released: Python 3.0 was actually terrible. It la…

Frankly, I still haven't seen a single reason to switch to Python3 beyond the fact that the original authors have gotten bored of providing security and bugfix updates and will stop in 2020. That's it. The only thing in the last decade or so of Python3's existence that even got me slightly interested in using it was asyncio, and after looking into it a bit, it frankly seems like more trouble than its worth. I know Py…

If you ever need to deal with encoding, you will very soon know why my friend. I've hated Python3 just as much but reality left me with no choice. It's time to say goodbye sooner rather than later.
Post reply on HN