[issue38853] set.repr breaches docstring contract

2019-11-19 Thread Cat Chenal


New submission from Cat Chenal :

S = {19,8,-1,25,0,1,2,3,4,5,6,7}
print('Set S = {{19,8,-1,25,0,1,2,3,4,5,6,7}}')

The set is represented by a new string-ordered set:
print(f'Its repr is:\n{S}\n')
Output:
{0, 1, 2, 3, 4, 5, 6, 7, 8, 19, 25, -1}

This is a breach of the contract stated in the docstring: "Build an unordered 
collection of unique elements."

--
components: ctypes
messages: 356991
nosy: Ylem
priority: normal
severity: normal
status: open
title: set.repr breaches docstring contract
type: behavior
versions: Python 3.6

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



[issue38855] test_unpack.py does not catch the unpacking of a set

2019-11-19 Thread Cat Chenal


New submission from Cat Chenal :

S = {19,8,-1,25,0,1,2,3,4,5,6,7}

a, *b, c = S
print('a:', a)
print('b:', b)
print('c:', c)

Output:
a: 0
b: [1, 2, 3, 4, 5, 6, 7, 8, 19, 25]
c: -1

Either test_unpack.py needs a test for "non-indexable object" to prevent this 
unpacking of a non-sequence, or the unpacking of a set should be implemented 
(granted the ordered repr of a set is changed to unordered, see Issue38853).

Being able to "unpack" a set would be nice to have, imho, because one would use 
that operation to obtain a partition (over unordered elements).

--
components: Tests, ctypes
messages: 356994
nosy: Ylem
priority: normal
severity: normal
status: open
title: test_unpack.py does not catch the unpacking of a set
versions: Python 3.6

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



[issue38853] set.repr breaches docstring contract

2019-11-20 Thread Cat Chenal


Cat Chenal  added the comment:

Thank you for pointing out my lack of clarity: I apologize.
I probably should not have split this issue in two (issue38855).

My confusion stems from the fact that I expected the unpacking of a set to 
return the same output as that obtained from the unpacking of a list.
>From my testing, I gather that the unpacking of a set is performed via its 
>repr, which uses "some ordering".

In closing, I want to note two points:

1. repr is apparently platform-dependent (here: Python 3.6.7 [MSC v.1900 64 bit 
(AMD64)]):

The code given by steven.daprano run in a jupyter lab cell or in VS Code yields 
a different output:
>>> repr({4, 5, 2**31+1, 2, 2**31+2, 3, 2**31, 0})
'{2147483648, 2147483649, 2, 2147483650, 4, 5, 3, 0}'

2. Testing reviewer's assertion: "The specific order you see will depend on the 
specific values in the set, as well as the order that they were inserted, 
deleted, and/or re-inserted in some arbitrary way."
This counter example, where element 0 is moved to the second position, shows 
that there is not such order dependence: 
>>> repr({4, 0, 5, 2**31+1, 2, 2**31+2, 3, 2**31})
'{0, 2147483649, 2, 2147483650, 4, 5, 3, 2147483648}'

--

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