Live data from Hacker News

What’s New in Python 3.8

docs.python.org

231–240 of 381 posts

Re: What’s New in Python 3.8

#231
post #22

As a developer who has primarily developed applications in Python for his entire professional career, I can't say I'm especially excited about any of the "headlining" features of 3.8. The "walrus operator" will occasionally be useful, but I doubt I will find many effective uses for it. Same with the forced positional/keyword arguments and the "self-documenting" f-string expressions. Even when they have a use, it's us…

> As a developer who has primarily developed applications in Python for his entire professional career, I can't say I'm especially excited about any of the "headlining" features of 3.8. Python is a fairly old, mature language. What features would you have been especially excited about?

I wouldn’t mind cpython performance improvements over language features. Specifically startup time. Py cli tools can easily take up to 300-600ms to start. Now, try to use them for scripting. A single script doing a bunch of calls to python clis has already several seconds of runtime penalty.

Re: What’s New in Python 3.8

#232
post #188

Earlier quoted context omitted.

I'd really like a way to refer to a variable in a outer scope (like global... but not just for global variables).

In the same vein, they could add syntax to distinguish introducing a variable from setting the value of an existing variable. Python's heuristics for that are pretty annoying.

I think that feature has exactly zero chances of getting adopted, but that's probably one of my top Python annoyances too.

If it's any consolation, the scope of a variable isn't determined by heuristics, it's just that the rules are (IMO) kinda bad. Basically, if a variable is assigned (in addition to `=` and friends, `import`, `class` and `def` are also assignments in disguise) to in what Python calls a "block" (which is not like a C-style block; rather `class` body, `def` body, or top-level) it is considered to belong to that block (with the notable exception of the name for a caught exception in a `except Exception as e: ...`, see [1]). If you want it to refer to a variable outside the block, you need to use `global` or `nonlocal` as appropriate. The full gory details are in [2]

1: https://docs.python.org/3/reference/compound_stmts.html#the-...

2: https://docs.python.org/3/reference/executionmodel.html#nami...

Re: What’s New in Python 3.8

#233
post #224

Earlier quoted context omitted.

f-strings are great. Much nicer than ".format". I hope in a next iteration of the language all strings will be f-strings by default, avoiding the need to prefix them by a silly "f".

That would of course be an absolute disaster, given that any user input could easily leak internal state and/or break your program.

I meant for inline strings (i.e., typed by the programmer). This is an inoffensive change. The only possible ``accident'' is when the programmer wants to write "{x}" instead of the value of x. This is such and exceptional case that it may be best treated by forcing to escape the curly brackets.

If anything, user-input strings must be treated as tainted whatever the case.

Re: What’s New in Python 3.8

#234
post #55

I don't mind the walrus operator, but holy cow the "positional operators" syntax is completely unintelligble...what the hell were they thinking?!

It really is not supposed to be used unless you are wrapping a C library. Or at least that’s the original reasoning, I think. Let’s hope it doesn’t get abused.

Re: What’s New in Python 3.8

#235
post #227
post #92

Earlier quoted context omitted.

The issue, in my opinion, is when you want something like this: while m := f(many, args): # do stuff with m Now, if you're writing this in Python 3.7, you often end up with some code duplication: m = f(many, args) while m: # do stuff with m m = f(many, args) # duplicate Or something like this: while True: m = f(many, args) if not m: break # do stuff with m Personally, I consider the last version to be the most elegan…

The last version clearly exposes that you have an infinite loop. This is something hidden by the `while(evaluate)` expression. Also if it comes to pure form I would have preferred `while (evaluate) as x:` out of establishing a parallel with existing syntax, but that's not very important.

On the contrary: the loop isn’t fundamentally infinite, it’s just an artefact of the language that you have to write it that way. The walrus lets you put the termination where it belongs.

Re: What’s New in Python 3.8

#237
post #22

As a developer who has primarily developed applications in Python for his entire professional career, I can't say I'm especially excited about any of the "headlining" features of 3.8. The "walrus operator" will occasionally be useful, but I doubt I will find many effective uses for it. Same with the forced positional/keyword arguments and the "self-documenting" f-string expressions. Even when they have a use, it's us…

In my opinion it was a mistake to reject the labelled break PEP

Re: What’s New in Python 3.8

#238
post #190
post #101

Earlier quoted context omitted.

There is a similar trick that you can use without the walrus operator. I wrote the code many years ago and I am reproducing this from memory, so the code below may be a little off. Define this class: class Any: def __eq__(self, other): self.value = other return True Then you can use an instance of it as the hole in a pattern. My use case was performing peephole optimizations in a simple 6502 assembler. For example, i…

But that breaks normal equality tests for your type?

Wouldn’t parent’s code simply copy into Any every time it’s compared in a list?

It is some spooky action at a distance.

Re: What’s New in Python 3.8

#239
post #150

The expansion of f-strings is a welcome addition. The more I use them, the happier I am that they exist https://docs.python.org/3/whatsnew/3.8.html#f-strings-suppor...

Why didn’t Python ship with the opposite functionality as well? Parsing instead of formatting. Given a string and a format string, return a list of variables (or a dictionary).

I think this is what you want:

https://github.com/r1chardj0n3s/parse

Re: What’s New in Python 3.8

#240
post #155
post #22

As a developer who has primarily developed applications in Python for his entire professional career, I can't say I'm especially excited about any of the "headlining" features of 3.8. The "walrus operator" will occasionally be useful, but I doubt I will find many effective uses for it. Same with the forced positional/keyword arguments and the "self-documenting" f-string expressions. Even when they have a use, it's us…

PEP-3136 was proposed and discussed more than 10 years ago in the 2->3 process. The python community was very different then. As an example, Python 3 was also the language that removed the function argument tuple packing, to which my reaction is basically WTF.

Is WTF related to the point of efficiency or some esoteric semantics?
Post reply on HN