Add set.union and set.intersection aliases to set.__ior__ and set.__i… #684
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks right - but the test isn't actually testing what you think it is. Beef up the test, and this should be ready to go!
self.assertCodeExecution(""" | ||
a = {'a', 'b', 'c'} | ||
b = {'a', 'c', 'd'} | ||
a.union(b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this is executes the right code, it won't actually test anything. assertCodeExecution()
performs a comparison of the output of executed code - so, this test will verify that the code doesn't output anything. This will verify that the code runs without error, but won't verify that the output is actually correct.
To test that the output is correct, you have to print the result of the operation so that there is something to compare.
self.assertCodeExecution(""" | ||
a = {'a', 'b', 'c'} | ||
b = {'a', 'c', 'd'} | ||
a.intersection(b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with union
, a print statement (or something else that generates output) is required.
self.assertCodeExecution(""" | ||
a = {'a', 'b', 'c'} | ||
b = {'a', 'c', 'd'} | ||
a.__ior__(b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check of __ior__
isn't needed - it's covered automatically by the InlineBinaryOperationTests.
self.assertCodeExecution(""" | ||
a = {'a', 'b', 'c'} | ||
b = {'a', 'c', 'd'} | ||
a.__iand__(b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check of __iand__
isn't needed - it's covered automatically by the InlineBinaryOperationTests.
Hi there! It looks like this PR might be dead, so we're closing it for now. Feel free to re-open it if you'd like to continue, or think about directing your efforts to https://github.com/beeware/briefcase or https://github.com/beeware/toga. Both of these have more active development right now. 😄 |
set.union
andset.intersection
are two frequently used methods of a set. Issue #478 added theset.__ior__
andset.__iand__
methods which are equivalent–although.union
and.intersection
are more standard (as they aren't dunder methods) and are used in a few modules in the python standard library.PR Checklist: