Live data from Hacker News

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

bugs.python.org

11–20 of 53 posts

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

#12

I can also do this, which is harmful. >>> True = False >>> False = True

The second line doesn't do anything though, since you already reassigned True to False it's like assigning False to False.

You could write (False, True) = (True, False) though.

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

#13

I 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 () = []

#14

I can also do this, which is harmful. >>> True = False >>> False = True

Python 3 removed this feature unfortunately.

Unfortunately? I'd love to know when changing false to mean true and vice-versa would make sense in any codebase.

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

#15

I can also do this, which is harmful. >>> True = False >>> False = True

Python 3 removed this feature unfortunately.

>>> (False, True) = (True, False)

>>> 1 if False else 0

1

>>> bool(0) == False

False

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

#17
post #8

Earlier quoted context omitted.

As an occasional numpy contributor, I would call this a bug.

Good point - I found it after it caused a really weird bug in a library I use. I'll open an issue on github...

Turns out it's deprecated:

    >>> import warnings
    >>> warnings.simplefilter('always')
    >>> 'x'*np.float64(3.5)
    __main__:1: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
    'xxx'

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

#18
post #8

This is a fun numpy quirk: >>> 'x'*3.5 Traceback (most recent call last): File " ", line 1, in TypeError: can't multiply sequence by non-int of type 'float' >>> import numpy as np >>> print 'x'*np.float64(3.5) xxx

As an occasional numpy contributor, I would call this a bug.

Yes, the expected output is xx›

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

#19

Earlier quoted context omitted.

Python 3 removed this feature unfortunately.

>>> (False, True) = (True, False) >>> 1 if False else 0 1 >>> bool(0) == False False

Not entirely sure of your point but...

Python 3.4.0 (default, Apr 11 2014, 13:05:11)

[GCC 4.8.2] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> (True, False) = (False, True)

  File "", line 1
SyntaxError: can't assign to keyword

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

#20

Earlier quoted context omitted.

Python 3 removed this feature unfortunately.

>>> (False, True) = (True, False) >>> 1 if False else 0 1 >>> bool(0) == False False

But, like the parent said, in Python 3:

    >>> (False, True) = (True, False)
      File "", line 1
    SyntaxError: can't assign to keyword
Post reply on HN