python / cpython

The Python programming language
https://www.python.org
Other
63.12k stars 30.22k forks source link

Please sort assertSetEqual's output #80411

Open 203af6e9-6337-4047-a625-d90d36ff5221 opened 5 years ago

203af6e9-6337-4047-a625-d90d36ff5221 commented 5 years ago
BPO 36230
Nosy @rhettinger, @rbtcollins, @ezio-melotti, @voidspace, @Windsooon, @remilapeyre, @j3ska

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = 'https://github.com/voidspace' closed_at = None created_at = labels = ['3.8', 'type-feature', 'library'] title = "Please sort assertSetEqual's output" updated_at = user = 'https://github.com/j3ska' ``` bugs.python.org fields: ```python activity = actor = 'remi.lapeyre' assignee = 'michael.foord' closed = False closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'Jess' dependencies = [] files = [] hgrepos = [] issue_num = 36230 keywords = [] message_count = 9.0 messages = ['337443', '337445', '337447', '337449', '337451', '337457', '337467', '337539', '343054'] nosy_count = 7.0 nosy_names = ['rhettinger', 'rbcollins', 'ezio.melotti', 'michael.foord', 'Windson Yang', 'remi.lapeyre', 'Jess'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue36230' versions = ['Python 3.8'] ```

203af6e9-6337-4047-a625-d90d36ff5221 commented 5 years ago

Currently https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertSetEqual returns a random list, but I'd like to see it sorted for ease of reading which running tests.

Should be small, but useful. Happy to make the edit myself, but have no clue how to send you changes.

23982c60-ed6c-47d1-96c2-69d417bd81b3 commented 5 years ago

Hi Jess, I think this could be added.

I think it should require only a a sort in https://github.com/python/cpython/blob/0f221d09cad46bee38d1b7a7822772df66c53028/Lib/unittest/case.py#L1127-L1138, to update the tests and add a blurb.

You will need to get Python source code at https://github.com/python/cpython and you can get information about how to contribute to Python in the dev guide : https://devguide.python.org/

If you need help, I would be happy to assist you and to review your pull request.

If you don't have time to work on this issue, I think we could keep it for the next mentored sprint.

203af6e9-6337-4047-a625-d90d36ff5221 commented 5 years ago

Wow! Thank you, very fast and the precise snippet of info I needed. Will try to send something off today. Very exciting.

rhettinger commented 5 years ago

I think it should require only a a sort

It's possible to have non-sortable elements in the set, so you'll either need to sort on the repr of the elements or have a fallback:

    assertSetEqual({10, None, 'abc'}, {20, 3+4j, 10})
3db4c488-648f-4df6-97a9-da1ac9fc355c commented 5 years ago

Just to be clear, as Raymond said, when we have two non-sortable objects (for instance, two instances which their class didn't implement the __lt and __gt methods), we should compare their repr() without sort() like now.

23982c60-ed6c-47d1-96c2-69d417bd81b3 commented 5 years ago

@rhettinger

It's possible to have non-sortable elements in the set, so you'll either need to sort on the repr of the elements or have a fallback

Yes, it is the repr that is used in the loop and that what's the sorting needs to be done against.

@Windson Yang

we should compare their repr() without sort() like now.

I'm not sure to understand, can you provide more information about what you are thinking of?

Is there a reason to add 2.7, 3.4, 3.5, 3.6 and 3.7 to versions affected ?

As far as I can tell, this is a new feature and should only go in 3.8.

3db4c488-648f-4df6-97a9-da1ac9fc355c commented 5 years ago

My point is careful about the non-sortable object. My mistake, this should be an enhancement, not a bug.

203af6e9-6337-4047-a625-d90d36ff5221 commented 5 years ago

Good call on the repr(), hadn't noted the "3+4j" issue - __gt and __lt do work for compare there, but not sorted(). *shrug* Will make sure the solution takes that into account in some fashion.

Bit slower as I expected as setting up the windows env has some bits that are not entirely happy.

23982c60-ed6c-47d1-96c2-69d417bd81b3 commented 5 years ago

Hi Jess, are you still working on this?