[issue26020] set_display evaluation order doesn't match documented behaviour

2016-01-06 Thread Hamish Campbell

Hamish Campbell added the comment:

> Do you have a use case where `x == y`/`hash(x) == hash(y)` does not mean that 
> `x` and `y` should be interchangeable? True and 1 are 100% interchangeable, 
> minus their str() output, and my example is very unlikely to ever appear in 
> actual code.

No I don't have a use case :)

> The culprit is the BUILD_SET opcode in Python/ceval.c which unnecessarily 
> loops backwards (it looks like it was copied from the BUILD_TUPLE opcode).

Incidentally, pypy seems to behave the same as reported here.

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26020>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26020] set_display evaluation order doesn't match documented behaviour

2016-01-05 Thread Hamish Campbell

New submission from Hamish Campbell:

It looks like the behaviour of set displays do not match behaviour in some 
cases. The documentation states:

"A set display yields a new mutable set object, the contents being specified by 
either a sequence of expressions or a comprehension. When a comma-separated 
list of expressions is supplied, its elements are evaluated from left to right 
and added to the set object. When a comprehension is supplied, the set is 
constructed from the elements resulting from the comprehension."

Note the following:

   >>> foo = { True, 1 }
   >>> print(foo)
   {1}

However, if we add elements 'left to right':

   >>> foo = set()
   >>> foo.add(True)
   >>> foo.add(1)
   >>> print(foo)
   {True}

Note that similar documentation for dict displays produces the expected result.

"If a comma-separated sequence of key/datum pairs is given, they are evaluated 
from left to right to define the entries of the dictionary: each key object is 
used as a key into the dictionary to store the corresponding datum. This means 
that you can specify the same key multiple times in the key/datum list, and the 
final dictionary’s value for that key will be the last one given."

   >>> foo = {}
   >>> foo[True] = 'bar'
   >>> foo[1] = 'baz'
   >>> print(foo)
   {True: 'baz'}

Which matches the dict display construction:

   >>> foo = { True: 'bar', 1: 'baz'}
   >>> print(foo)
   {True: 'baz'}

Note that I've tagged this as a documentation bug, but it seems like the 
documentation might be the preferred implementation.

--
assignee: docs@python
components: Documentation
messages: 257579
nosy: Hamish Campbell, docs@python
priority: normal
severity: normal
status: open
title: set_display evaluation order doesn't match documented behaviour
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26020>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26020] set_display evaluation order doesn't match documented behaviour

2016-01-05 Thread Hamish Campbell

Hamish Campbell added the comment:

Note also the differences here:

   >>> print(set([True, 1]))
   {True}
   >>> print({True, 1})
   {1}
   >>> print({x for x in [True, 1]})
   {True}

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26020>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26020] set_display evaluation order doesn't match documented behaviour

2016-01-05 Thread Hamish Campbell

Hamish Campbell added the comment:

Apologies, that first line should read "It looks like the documentation of set 
displays do not match behaviour in some cases".

--

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26020>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com