improve test_copy_reduce and test_deepcopy_reduce coverage - #154182
Conversation
|
Rather than modifying existing tests, could you create new tests for the |
Since the existing tests are named Maybe I gave the PR a confusing name and should have named it something like "Fix test_copy_reduce and "test_deepcopy_reduce". |
|
Ah I see, I didn't notice there was already a test for def __reduce_ex__(self):
self.fail("shouldn't call this") |
I don't think I can. The point is In the existing version of the test because no I want to make sure |
This should work no? Unless I'm missing something? class C(object):
def __reduce_ex__(self, proto):
self.fail("shouldn't call this")
def __reduce__(self):
c.append(1)
return ""
def __getattribute__(self, name):
if name == "__reduce_ex__":
raise AttributeError(name)
return object.__getattribute__(self, name)Also, unrelated, but the |
Sorry, I misunderstood. Of course I can add the |
|
Ah sorry, I wasn't clear about what I meant.. I'd just fix the |
I am unsure how to handle it. Should I just rename the parameter? What new name do you propose? Should I replace |
|
I think renaming the inner def __reduce_ex__(*args):
self.fail("shouldn't call this") |
Done :-) |
|
Also needs to be fixed in |
@tomasr8 Done. Sorry for my long inactivity. |
|
Thanks for the PR @dslavicek! |
|
Thanks @dslavicek for the PR, and @tomasr8 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
GH-155792 is a backport of this pull request to the 3.15 branch. |
|
GH-155793 is a backport of this pull request to the 3.14 branch. |
|
GH-155794 is a backport of this pull request to the 3.13 branch. |
…-154182) (#155794) improve test_copy_reduce and test_deepcopy_reduce coverage (GH-154182) * improve test_copy_reduce and test_deepcopy_reduce coverage * add assert __reduce_ex__ not called * change reduce params in test copy and deepcopy reduce_ex * change reduce_ex params in test copy and deepcopy reduce --------- (cherry picked from commit 4af81d9) Co-authored-by: David <slavicek.david29@gmail.com> Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
…-154182) (#155793) improve test_copy_reduce and test_deepcopy_reduce coverage (GH-154182) * improve test_copy_reduce and test_deepcopy_reduce coverage * add assert __reduce_ex__ not called * change reduce params in test copy and deepcopy reduce_ex * change reduce_ex params in test copy and deepcopy reduce --------- (cherry picked from commit 4af81d9) Co-authored-by: David <slavicek.david29@gmail.com> Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Line 94 in
copy()method and line 150 indeepcopy()method were not covered by tests. This happened because thereductor = getattr(x, "__reduce_ex__", None)at lines 88 and 144 took__reduce_ex__from theobjectclass which preventing reaching theelseblock where__reduce__is checked.This PR adds coverage for those two lines and by this increases branch coverage of the copy module to 100%.
printscreen of coverage check on main:
