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.

Python bug: Can assign [] = (), but not () = []

85 pointsby axitalmost 10 years ago

11 comments

iawalmost 10 years ago
I was very impressed with the collective thought process shown in the bug thread. It was quite constructive and I think demonstrative of why python has been such a successful project.
评论 #9611677 未加载
ngoldbaumalmost 10 years ago
This is a fun numpy quirk:<p><pre><code> &gt;&gt;&gt; &#x27;x&#x27;*3.5 Traceback (most recent call last): File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt; TypeError: can&#x27;t multiply sequence by non-int of type &#x27;float&#x27; &gt;&gt;&gt; import numpy as np &gt;&gt;&gt; print &#x27;x&#x27;*np.float64(3.5) xxx</code></pre>
评论 #9609647 未加载
评论 #9609631 未加载
评论 #9614604 未加载
agumonkeyalmost 10 years ago
Dave Beazley gave a talk showing this. See <a href="https:&#x2F;&#x2F;twitter.com&#x2F;renfredxh&#x2F;status&#x2F;586653125970386945" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;renfredxh&#x2F;status&#x2F;586653125970386945</a>
ameliusalmost 10 years ago
This is mostly harmless, as most people in that thread already noted.
tenfingersalmost 10 years ago
Using [] = to exhaust generators (as mentioned in the bug report) is actually pretty awesome in my mind.
rectangletanglealmost 10 years ago
&gt;&gt;&gt; [a, b] = 2, 3<p>&gt;&gt;&gt; (a, b) = 2, 3<p>&gt;&gt;&gt; {a, b} = 2, 3<p><pre><code> File &quot;&lt;interactive input&gt;&quot;, line 1 </code></pre> SyntaxError: can&#x27;t assign to literal
评论 #9609920 未加载
sparakeralmost 10 years ago
This is what i see in javascript:<p>[] = (); VM105:2 Uncaught ReferenceError: Invalid left-hand side in assignment<p>() = []; VM114:2 Uncaught SyntaxError: Unexpected token )
ixtlialmost 10 years ago
&gt; The starting point is recognizing that this has been around for very long time and is harmless.
ronbeltranalmost 10 years ago
I can also do this, which is harmful.<p><pre><code> &gt;&gt;&gt; True = False &gt;&gt;&gt; False = True</code></pre>
评论 #9609782 未加载
评论 #9609753 未加载
评论 #9609721 未加载
评论 #9615346 未加载
squigs25almost 10 years ago
() is not a tuple. (a,b) is a tuple or (a,) would also be a tuple.
评论 #9615952 未加载
rectangletanglealmost 10 years ago
....__class__ # Python 3 only