Comparing Python enums to Java, was: How much sanity checking is required for function inputs?

Chris Angelico rosuav at gmail.com
Sun Apr 24 12:10:05 EDT 2016


On Mon, Apr 25, 2016 at 2:04 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Unfortunately, the empty tuple tends to be a singleton, so there is no way
> to tell that red and default are (supposed to be) the same and blue is
> (supposed to be) different:
>
> --> a = b = ()
> --> c = ()
> --> a is b
> True
> --> a is c
> True
>
> If you have an idea on how to make that work I am interested.

Easy: allow an empty list to have the same meaning as an empty tuple.
Every time you have [] in your source code, you're guaranteed to get a
new (unique) empty list, and then multiple assignment will work.

ChrisA



More information about the Python-list mailing list