TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What’s New in Python 3.8

833 pointsby supakeenover 5 years ago

40 comments

CivBaseover 5 years ago
As a developer who has primarily developed applications in Python for his entire professional career, I can&#x27;t say I&#x27;m especially excited about any of the &quot;headlining&quot; features of 3.8.<p>The &quot;walrus operator&quot; will occasionally be useful, but I doubt I will find many effective uses for it. Same with the forced positional&#x2F;keyword arguments and the &quot;self-documenting&quot; f-string expressions. Even when they have a use, it&#x27;s usually just to save one line of code or a few extra characters.<p>The labeled breaks and continues proposed in PEP-3136 [0] also wouldn&#x27;t be used very frequently, but they would at least eliminate multiple lines of code and reduce complexity.<p>PEP-3136 was rejected because &quot;code so complicated to require this feature is very rare&quot;. I can understand a stance like that. Over complicating a language with rarely-used features can definitely create problems. I just don&#x27;t see why the three &quot;headline&quot; features I mentioned are any different.<p>[0]: <a href="https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-3136&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-3136&#x2F;</a>
评论 #21253983 未加载
评论 #21256412 未加载
评论 #21254049 未加载
评论 #21253902 未加载
评论 #21253705 未加载
评论 #21253808 未加载
评论 #21254528 未加载
评论 #21255438 未加载
评论 #21259077 未加载
评论 #21256191 未加载
评论 #21257556 未加载
评论 #21256276 未加载
评论 #21267117 未加载
评论 #21256641 未加载
评论 #21253580 未加载
robocatover 5 years ago
<p><pre><code> def f(a, b, &#x2F;, c, d, *, e, f): </code></pre> Wow: IMHO that is a very ugly syntax to define a fn with 6 parameters, although it looks to be a path dependency on previous decisions (*, and CPython ,&#x2F;) and clearly there was much discussion of the need for the functionality and the compromises: <a href="https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0570&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0570&#x2F;</a><p>It amazes me to see how certain features make it into languages via community&#x2F;committee (octal numbers in JavaScript - arrgh!).<p>One thing I find really difficult to deal with in languages is the overloading of different syntactic(edit:semantic) usages of different symbols, which itself is a result of limiting ourselves to the ASCII symbols that can be typed. I don&#x27;t recall written mathematics having the issue badly (although I haven&#x27;t had to write any for a long time!).
评论 #21253729 未加载
评论 #21253689 未加载
评论 #21253644 未加载
评论 #21254177 未加载
评论 #21253665 未加载
Xophmeisterover 5 years ago
This got missed from the release announcement, but now there&#x27;s `functools.singledispatchmethod`,[1] as the class method sibling to `functools.singledispatch`.[2] This allows you to overload the implementation of a function (and now a method) based on the type of its first argument. This saves you writing code like:<p><pre><code> def foo(bar): if isinstance(bar, Quux): # Treat bar as a Quux elif isinstance(bar, Xyzzy): # Treat bar as an Xyzzy # etc. </code></pre> I understand runtime type checking like that is considered a bit of a Python antipattern. With `singledispatch`, you can do this instead:<p><pre><code> @singledispatch def foo(bar:Quux): # Quux implementation @foo.register def _(bar:Xyzzy): # Xyzzy implementation </code></pre> With `singledispatchmethod`, you can now also do this to class methods, where the type of the first non-self&#x2F;class is used by the interpreter to check the type, based on its annotation (or using the argument to its `register` method). You could mimic this behaviour using `singledispatch` in your constructor, but this syntax is much nicer.<p>[1] <a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;functools.html#functools.singledispatchmethod" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;functools.html#functools.s...</a><p>[2] <a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;functools.html#functools.singledispatch" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;functools.html#functools.s...</a>
评论 #21257492 未加载
评论 #21258221 未加载
评论 #21256925 未加载
评论 #21256929 未加载
airstrikeover 5 years ago
The expansion of f-strings is a welcome addition. The more I use them, the happier I am that they exist<p><a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;whatsnew&#x2F;3.8.html#f-strings-support-for-self-documenting-expressions-and-debugging" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;whatsnew&#x2F;3.8.html#f-strings-suppor...</a>
评论 #21253525 未加载
评论 #21253433 未加载
评论 #21253414 未加载
评论 #21255358 未加载
metalliqazover 5 years ago
This is the release that contains the controversial assignment expressions, which sparked the debate that convinced GvR to quit as BDFL.<p>They didn&#x27;t select my preferred syntax, but I&#x27;m still looking forward to using assignment expressions for testing my re.match() objects.<p>I haven&#x27;t used 3.8.0 yet but I hope its a good one because 2020 is the year that 2.7 dies and there will be a lot of people switching.
评论 #21253329 未加载
评论 #21258446 未加载
评论 #21253712 未加载
评论 #21253431 未加载
mintplantover 5 years ago
Buried in the notes for the `typing` module:<p>&gt; “Final” variables, functions, methods and classes. See PEP 591, typing.Final and typing.final(). The final qualifier instructs a static type checker to restrict subclassing, overriding, or reassignment:<p>&gt; pi: Final[float] = 3.1415926536<p>As I understand it, this means Python now has a way of marking variables as constant (though it doesn&#x27;t propagate into the underlying values as in the case of C++&#x27;s `const`).<p>The equivalent Java:<p><pre><code> final float pi = 3.1415926536;</code></pre>
评论 #21259907 未加载
评论 #21255925 未加载
amanziover 5 years ago
Real Python have a great post out today going through most of the changes: <a href="https:&#x2F;&#x2F;realpython.com&#x2F;python38-new-features&#x2F;" rel="nofollow">https:&#x2F;&#x2F;realpython.com&#x2F;python38-new-features&#x2F;</a><p>They have a lot of code samples and examples about how and when to use the new features.Personally, I love the new debugging support in F strings.
评论 #21253727 未加载
ohaziover 5 years ago
&gt; The typing module incorporates several new features:<p>&gt; A dictionary type with per-key types.<p>Ah, I&#x27;ve been waiting for this. I&#x27;ve been able to use Python&#x27;s optional types pretty much everywhere <i>except</i> for dictionaries that are used as pseudo-objects, which is a fairly common pattern in Python. This should patch that hole nicely.
评论 #21253465 未加载
评论 #21255116 未加载
supakeenover 5 years ago
Arguably one of the hotter debated functions is assignment-as-expression through the := or walrus operator.<p>Quite happy with the new SyntaxWarning for identity comparison on literals and missing commas :)<p>Especially neat is also the `python -m asyncio` shell which allows you to run top-level awaits in your repl instead of needing to start a new event loop each time!
评论 #21253477 未加载
pcr910303over 5 years ago
I like the additions of the f-strings and walrus operator, but I find myself wishing a breaking-release removing the old features that the new features covers. Python&#x27;s philosophy was to have one way to do something, but the current situation of Python is very inconsistent. Python 3 has like 4~5 ways to format strings, and due to the addition of the walrus operator, we have (I understand the differences between := and = but) two different syntaxes for variable declaration&#x2F;assignment.<p>I understand that Python can&#x27;t break all kinds of code (as the 2-&gt;3 conversion is still a pain), but still I imagine a Python-esque language without all the warts that Python have with it&#x27;s &#x27;organic&#x27; growth.
评论 #21255788 未加载
评论 #21256055 未加载
brataoover 5 years ago
I do not know exactly what caused this, but my internal project test-suite got a much appreciated 5% speedup! Thank you Python team!
评论 #21253484 未加载
评论 #21253722 未加载
svaraover 5 years ago
&gt; Added new multiprocessing.shared_memory module<p>Hard to understand why this is so far down. This is fantastic news!
评论 #21254480 未加载
Pxtlover 5 years ago
Ugh, I hate assignment expressions. I liked that they were missing from Python.<p>I&#x27;ve been coding in algolesque languages for 20 years and hiding assignments inside of expressions instead of putting them on the left like a statement has always tripped me up.
评论 #21254764 未加载
w-mover 5 years ago
&gt; The list constructor does not overallocate the internal item buffer if the input iterable has a known length (the input implements __len__). This makes the created list 12% smaller on average. (Contributed by Raymond Hettinger and Pablo Galindo in bpo-33234.)<p>Wow. I believe it&#x27;s a stated goal of CPython to prefer simple maintainable code over maximum performance. But relatively low-hanging fruit like this makes me wonder how much overall CPython perf could be improved by specialising for a few more of these.
archie2over 5 years ago
I don&#x27;t mind the walrus operator, but holy cow the &quot;positional operators&quot; syntax is completely unintelligble...what the hell were they thinking?!
评论 #21256539 未加载
santiagobasultoover 5 years ago
Shared Memory is the star of this release IMHO.
评论 #21253439 未加载
评论 #21253509 未加载
herpderperatorover 5 years ago
Damn... this is rather confusing: <a href="https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0572&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0572&#x2F;</a><p>I really like the walrus operator, but I didn&#x27;t realize how many &quot;you shouldn&#x27;t do this&quot; and &quot;this is too hard already&quot; cases exist where they are discouraging using the walrus operator.
jxyover 5 years ago
It&#x27;s interesting to see Python&#x27;s gradual acceptance to TMTOWTDI.
blumomoover 5 years ago
The new assignment expression is great and I wish that an optional operator (`?`) and Elvis operator (`?:`) will make it to Python one day, too. I would love to write:<p><pre><code> v = obj?.prop1?.prop2 ?: &quot;default&quot; </code></pre> instead of long if conditions:<p><pre><code> v = obj.prop1.prop2 if obj and obj.prop1 and obj.prop1.prop2 else &quot;default&quot; </code></pre> A PEP for Python 3.8 existed but has been deferred: <a href="https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0505&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.python.org&#x2F;dev&#x2F;peps&#x2F;pep-0505&#x2F;</a>
agfover 5 years ago
I gave a talk on this at the PyBay conference this summer, and more recently at the ChiPy meetup in Chicago last week.<p>Presentation: <a href="https:&#x2F;&#x2F;docs.google.com&#x2F;presentation&#x2F;d&#x2F;1a3Zoav7NmeN_gXjGcV_lalROR8Mo8CxDpgV1qAdof9U&#x2F;edit?usp=sharing" rel="nofollow">https:&#x2F;&#x2F;docs.google.com&#x2F;presentation&#x2F;d&#x2F;1a3Zoav7NmeN_gXjGcV_l...</a><p>Video from PyBay: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=OtdQN24Z5MA" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=OtdQN24Z5MA</a><p>It covers assignment expressions in some depth, as well as highlights elsewhere.
sys_64738over 5 years ago
Looks like python is trying to out C++ the C++ language with kitchen sink bolt ons.
svnpennover 5 years ago
&gt; In this example, the assignment expression helps avoid calling len() twice:<p><pre><code> if (n := len(a)) &gt; 10: print(f&quot;List is too long ({n} elements, expected &lt;= 10)&quot;) </code></pre> Um, no it doesnt?:<p><pre><code> a1 = [10, 20, 30] n1 = len(a1) if n1 &gt; 2: print(f&#x27;{n1} is greater than two&#x27;)</code></pre>
评论 #21254999 未加载
评论 #21254514 未加载
louis8799over 5 years ago
New &quot;f-strings support = for self-documenting expressions&quot; but you cannot use f-strings as doc string ;)
nilsandreyover 5 years ago
The := operator is the assignment operator on Object Pascal, just saying, remembering my old days. BTW not so old for everyone -&gt; <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=15490345" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=15490345</a>
omginternetsover 5 years ago
I stepped away from Python for about a year, and now I&#x27;m coming back to it. I hardly recognize the language. I&#x27;m not happy about this at all.<p>I don&#x27;t really have a point, except that Python 3 feels like a moving target.
评论 #21257263 未加载
robomartinover 5 years ago
I don&#x27;t understand why the walrus operator is needed at all. Why not allow, this to work:<p><pre><code> if m=whatever(): do_something </code></pre> Why create a new assignment operator? For all the talk about making code not confusing, etc., some of these decisions sure seem nonsensical.<p>Oh, OK, it confuses passing arguments into a function by name? Really? C&#x27;mon.<p>Also, I can&#x27;t understand the nearly religious rejection of pre and post increment&#x2F;decrement (++&#x2F;--) and, for the love of Picard, the switch() statement.<p>I enjoy using Python but some of these things are just silly. Just my opinion, of course. What do I know anyhow? I&#x27;ve only been writing software for over thirty years while using over a dozen languages ranging from machine language (as in op codes) to APL and every new fad and modern language in between.<p>As I watch languages evolve what I see is various levels of ridiculous reinvention of the wheel for very little in the way of real gains in productivity, code quality, bug eradication, expressiveness, etc. Python, Objective-C, Javascript, PHP, C# and a bunch of other mutants are just C and C++ that behave differently. Sure, OK, not strictly true at a technical level, but I&#x27;ll be damned if it all doesn&#x27;t end-up with machine code that does pretty much the same darn thing.<p>The world did exist before all of these &quot;advanced&quot; languages were around and we wrote excellent software (and crappy software too, just like today).<p>What&#x27;s worse is that some of these languages waste a tremendous amount of resources and clock cycles to do the same thing we used to do in &quot;lower&quot; languages without any issues whatsoever. Mission critical, failure tolerant, complex software existed way before someone decided that the switch() statement was an abomination and that pre and post increment&#x2F;decrement are somehow confusing or unrefined. Kind of makes you wonder what mental image they have of a programmer, doesn&#x27;t it? Really. In my 30+ years in the industry I have yet to meet someone who is laid to waste, curled-up into a fetal position confused about pre and post increment&#x2F;decrement, switch statements and other things deemed too complex and inelegant in some of these languages and pedantic circles.<p>Geez!<p>&lt;&#x2F;rant off&gt;
molteanuover 5 years ago
Is Python now becoming the new C++?
评论 #21256233 未加载
评论 #21257281 未加载
vikinghckrover 5 years ago
Disappointing that Python sill has no support for a sorted container in its standard library, akin to C++ `set` or `map` classes.
评论 #21255190 未加载
评论 #21255263 未加载
评论 #21255014 未加载
varelazover 5 years ago
Everything of this looks like syntax sugar. I would expect more work on internals. Python has a lot of awkward edge cases in standard lib. In a lot of cases None is valid output for not-done states. Also I hate multithreading programming in Python 3, it has all drawbacks of C with additions of GIL.
spicyramenover 5 years ago
I&#x27;m still migrating from 2.7...to 3.5
ram_rarover 5 years ago
Does the python community care about concurrency at all? I havent seen anything new in terms of concurrency in a while. I might be wrong about this, but walrus operator seems like a gateway to writing obfuscated perlesque code.
评论 #21254544 未加载
评论 #21254496 未加载
cryptosover 5 years ago
It would be nice if the Python web site would be mobile friendly.
ameliaquiningover 5 years ago
Anyone else most excited about PYTHONCACHEPREFIX? :-P
评论 #21255530 未加载
maestover 5 years ago
Can I chain the walrus operator? All examples I&#x27;ve seen were part of if&#x2F;while blocks.<p>Something like:<p><pre><code> r1 = foo(x:=bar) r2 = baz(x)</code></pre>
Timothycquinnover 5 years ago
Assignment expression is something I miss from JavaScript which I used a lot to strip lines of code. Great to see in Python.
tolgahanuzunover 5 years ago
Updates on `f-string` are quite fun. :)<p>`f&#x27;{username= }&#x27;` &#x27;username=&quot;tolgahanuzun&quot;&#x27;<p>I like it.
cutlerover 5 years ago
Any idea how long it will take before it&#x27;s an option with pyenv?
qwerty456127over 5 years ago
Still no pattern matching and no immutable vars :-(
bp294over 5 years ago
Interesting! Thanks for the share!
heyflyguyover 5 years ago
man do I wish they would make multiprocessing easier
评论 #21254303 未加载