Skip to content

Commit 300a257

Browse files
committed
fix check for self_arg when class has __len__
Calling `if self` on a class that has a __len__ method calls this method (similar to how `if my_list` checks if the list is empty). We only want to check if self exists.
1 parent 3854494 commit 300a257

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

e2e_projects/my_lib/src/my_lib/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def to_origin(self):
7474
def ignored(self):
7575
self.foo = 'bar' # pragma: no mutate
7676

77+
def __len__(self):
78+
return 0
79+
7780
@staticmethod
7881
def from_coords(coords) -> 'Point':
7982
return Point(coords[0], coords[1])

mutmut/trampoline_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _mutmut_trampoline(orig, mutants, call_args, call_kwargs, self_arg = None):
6363
result = orig(*call_args, **call_kwargs)
6464
return result
6565
mutant_name = mutant_under_test.rpartition('.')[-1]
66-
if self_arg:
66+
if self_arg is not None:
6767
# call to a class method where self is not bound
6868
result = mutants[mutant_name](self_arg, *call_args, **call_kwargs)
6969
else:

tests/e2e/snapshots/my_lib.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"my_lib.x\u01c1Point\u01c1to_origin__mutmut_2": 1,
5757
"my_lib.x\u01c1Point\u01c1to_origin__mutmut_3": 0,
5858
"my_lib.x\u01c1Point\u01c1to_origin__mutmut_4": 0,
59+
"my_lib.x\u01c1Point\u01c1__len____mutmut_1": 33,
5960
"my_lib.x_escape_sequences__mutmut_1": 1,
6061
"my_lib.x_escape_sequences__mutmut_2": 0,
6162
"my_lib.x_escape_sequences__mutmut_3": 1,

0 commit comments

Comments
 (0)