Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document that TestCase.assertCountEqual() can take iterables #686

Merged
merged 2 commits into from Apr 23, 2019

Conversation

jkleint
Copy link
Contributor

@jkleint jkleint commented Mar 16, 2017

The docstring for assertCountEqual() says "An unordered sequence comparison," but in fact it works fine with general Iterables, since the first thing it does is make a defensive copy. Since order does not matter, we are not indexing into the arguments, it is necessary to read all elements to make a comparison, and a defensive copy is generally a good practice, there does not seem to be a reason to forbid iterables. That is, it is hard to imagine a situation where a list is fine but an iterable is not. (The only potential issue is if the same iterator object is passed as both arguments, but of course that is the nature of iterators.) This is, however, a change to the method contract and the implementation would have to remain consistent in the future.

I noticed the issue when using mypy, and typeshed has updated their stubs: python/typeshed#1006

The docstring for `assertCountEqual()` says "An unordered sequence comparison", but in fact it works fine with general Iterables, since the first thing it does is make a defensive copy.  Since order does not matter, we are not indexing into the arguments, it is necessary to read all elements to make a comparison, and a defensive copy is generally a good practice, there does not seem to be a reason to forbid iterables.  That is, it is hard to imagine a situation where a list is fine but an iterable is not.  (The only potential issue is if the same iterable object is passed as both arguments, but of course that is the nature of iterables.)

I noticed the issue when using mypy, and typeshed has updated their stubs: python/typeshed#1006
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow these steps to help rectify the issue:

  1. If you don't have an account on b.p.o, please create one
  2. Make sure your GitHub username is listed in "Your Details" at b.p.o
  3. If you have not already done so, please sign the PSF contributor agreement. The "bugs.python.org username " requested by the form is the "Login name" field under "Your Details".
  4. If you just signed the CLA, please wait at least one US business day and then check "Your Details" on bugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  5. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

@mention-bot
Copy link

@jkleint, thanks for your PR! By analyzing the history of the files in this pull request, we identified @benjaminp, @voidspace and @serhiy-storchaka to be potential reviewers.

Copy link
Contributor

@rhettinger rhettinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring wasn't well written to begin with. The proposed while technically correct makes in sound even more strange. I suggest a more thorough rewording, perhaps something like, "Asserts that two iterables have the same elements, the same number of times, without regard to order", or "Asserts that two iterables have the same elements, regardless of order and that if the same element occurs more than once, it occurs the same number of times."

@jkleint
Copy link
Contributor Author

jkleint commented May 11, 2017

Went with the first suggestion; thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants