Earlier quoted context omitted.
Only constant for certain values of "constant". ;) ( https://gist.github.com/Jach/1208215 works in Python 3 too.)
After “import ctypes”, all bets are off.
Python bug: Can assign [] = (), but not () = []
31–40 of 53 posts
Re: Python bug: Can assign [] = (), but not () = []
#32I can also do this, which is harmful. >>> True = False >>> False = True
Only in Python 2, since that is a backward-compatibility feature. (“False” and “True” used to be variables containing 0 and 1 before Python had true booleans, many ages ago.) Python 3 makes “True” and “False” be constant values, like “1” or “2”, like they should be.
Re: Python bug: Can assign [] = (), but not () = []
#33Earlier quoted context omitted.
>>> (False, True) = (True, False) >>> 1 if False else 0 1 >>> bool(0) == False False
In[2]: (True, False) = (False, True) In[3]: True Out[3]: False In[4]: 1 if False else 0 Out[4]: 1 In[5]: 'yes' if bool(0) == False else 'no' Out[5]: 'no' In[6]: bool(0) == False Out[6]: False What bothers me here is that when the interpreter says "False", it clearly means the opposite of (the new) False. So by reassigning True and False, I've actually caused inconsistent behavior in python, not just really-confusingl…
>>> A()
False
>>> bool(A())
True
>>> type(A())
A repr is just a representation in development context, nothing more and nothing less, there is no requirement that it be sensible or of any use, though that's certainly recommended (contrary to __str__/__unicode__ which should be silly): >>> B()
A gray parrot
The only "inconsistency" you've created is that False in the console's local namespace does not match __builtins__.False or the interpreter's internal False object. You can still access the former by the way: >>> False
True
>>> __builtins__.False
False
unless you also override it: >>> __builtins__.False = True
>>> __builtins__.False
True
the interpreter still does not care though, you've just broken any Python code relying on the builtin (you can actually alter the "true" False object via ctypes)Re: Python bug: Can assign [] = (), but not () = []
#34Re: Python bug: Can assign [] = (), but not () = []
#35Re: Python bug: Can assign [] = (), but not () = []
#36Re: Python bug: Can assign [] = (), but not () = []
#37I 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.
Re: Python bug: Can assign [] = (), but not () = []
#38Earlier quoted context omitted.
That could be because sets aren't ordered (even though it looks odd in this context).
I thought that at first too, but even then the exception seems spurious. It would be more inline with existing Python behavior to evaluate it as undefined/indeterminate assignment order (though this would be pretty useless). >>> a, b, c, d = {1, 2, 3, 'a'} >>> a 'a' Regardless, it shouldn't be surprising when writing insane code, that the language starts acting insane. Python as a whole is pretty decent when it comes…
[0]: https://docs.python.org/3/reference/simple_stmts.html#assign...
Re: Python bug: Can assign [] = (), but not () = []
#39Re: Python bug: Can assign [] = (), but not () = []
#40I 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.
If it was PHP they'd just write it down and claim it's documented behaviour.
Perhaps based on older versions of PHP or merely uninformed snark?