Skip to content

Commit 8889ba6

Browse files
committed
Ignore types for arg and kwarg, in case user function uses a parameter with name "arg"
1 parent 00778dc commit 8889ba6

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/mutmut/file_mutation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,14 @@ def _get_local_name(func_name: str) -> cst.BaseExpression:
316316
# return await _mutmut_trampoline(...)
317317
result_statement = cst.SimpleStatementLine([cst.Return(cst.Await(result))])
318318

319+
type_ignore_whitespace = cst.TrailingWhitespace(comment=cst.Comment('# type: ignore'))
320+
319321
function.whitespace_after_type_parameters
320322
return function.with_changes(
321323
body=cst.IndentedBlock(
322324
[
323-
cst.SimpleStatementLine([args_assignemnt]),
324-
cst.SimpleStatementLine([kwargs_assignment]),
325+
cst.SimpleStatementLine([args_assignemnt], trailing_whitespace=type_ignore_whitespace),
326+
cst.SimpleStatementLine([kwargs_assignment], trailing_whitespace=type_ignore_whitespace),
325327
result_statement,
326328
],
327329
),

tests/test_mutation regression.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def test_create_trampoline_wrapper_async_method():
1919

2020
assert _get_trampoline_wrapper(source, "x_foo__mutmut") == snapshot("""\
2121
async def foo(a: str, b, *args, **kwargs) -> dict[str, int]:
22-
args = [a, b, *args]
23-
kwargs = {**kwargs}
22+
args = [a, b, *args]# type: ignore
23+
kwargs = {**kwargs}# type: ignore
2424
return await _mutmut_trampoline(x_foo__mutmut_orig, x_foo__mutmut_mutants, args, kwargs, None)\
2525
""")
2626

@@ -34,8 +34,8 @@ async def foo():
3434

3535
assert _get_trampoline_wrapper(source, "x_foo__mutmut") == snapshot("""\
3636
async def foo():
37-
args = []
38-
kwargs = {}
37+
args = []# type: ignore
38+
kwargs = {}# type: ignore
3939
async for i in _mutmut_trampoline(x_foo__mutmut_orig, x_foo__mutmut_mutants, args, kwargs, None):
4040
yield i\
4141
""")
@@ -46,8 +46,8 @@ def test_create_trampoline_wrapper_with_positionals_only_args():
4646

4747
assert _get_trampoline_wrapper(source, "x_foo__mutmut") == snapshot("""\
4848
def foo(p1, p2=None, /, p_or_kw=None, *, kw):
49-
args = [p1, p2, p_or_kw]
50-
kwargs = {'kw': kw}
49+
args = [p1, p2, p_or_kw]# type: ignore
50+
kwargs = {'kw': kw}# type: ignore
5151
return _mutmut_trampoline(x_foo__mutmut_orig, x_foo__mutmut_mutants, args, kwargs, None)\
5252
""")
5353

@@ -59,8 +59,8 @@ def test_create_trampoline_wrapper_for_class_method():
5959
source, "x_foo__mutmut", class_name="Person"
6060
) == snapshot("""\
6161
def foo(self, a, b):
62-
args = [a, b]
63-
kwargs = {}
62+
args = [a, b]# type: ignore
63+
kwargs = {}# type: ignore
6464
return _mutmut_trampoline(object.__getattribute__(self, 'x_foo__mutmut_orig'), object.__getattribute__(self, 'x_foo__mutmut_mutants'), args, kwargs, self)\
6565
""")
6666

@@ -137,8 +137,8 @@ def x_foo__mutmut_2(a: list[int], b):
137137
return a[0] >= b
138138
139139
def foo(a: list[int], b):
140-
args = [a, b]
141-
kwargs = {}
140+
args = [a, b]# type: ignore
141+
kwargs = {}# type: ignore
142142
return _mutmut_trampoline(x_foo__mutmut_orig, x_foo__mutmut_mutants, args, kwargs, None)
143143
144144
x_foo__mutmut_mutants : ClassVar[MutantDict] = { # type: ignore
@@ -154,8 +154,8 @@ def x_bar__mutmut_1():
154154
yield 2
155155
156156
def bar():
157-
args = []
158-
kwargs = {}
157+
args = []# type: ignore
158+
kwargs = {}# type: ignore
159159
return _mutmut_trampoline(x_bar__mutmut_orig, x_bar__mutmut_mutants, args, kwargs, None)
160160
161161
x_bar__mutmut_mutants : ClassVar[MutantDict] = { # type: ignore
@@ -169,8 +169,8 @@ def xǁAdderǁ__init____mutmut_orig(self, amount):
169169
def xǁAdderǁ__init____mutmut_1(self, amount):
170170
self.amount = None
171171
def __init__(self, amount):
172-
args = [amount]
173-
kwargs = {}
172+
args = [amount]# type: ignore
173+
kwargs = {}# type: ignore
174174
return _mutmut_trampoline(object.__getattribute__(self, 'xǁAdderǁ__init____mutmut_orig'), object.__getattribute__(self, 'xǁAdderǁ__init____mutmut_mutants'), args, kwargs, self)
175175
\n\
176176
xǁAdderǁ__init____mutmut_mutants : ClassVar[MutantDict] = { # type: ignore
@@ -185,8 +185,8 @@ def xǁAdderǁadd__mutmut_1(self, value):
185185
return self.amount - value
186186
187187
def add(self, value):
188-
args = [value]
189-
kwargs = {}
188+
args = [value]# type: ignore
189+
kwargs = {}# type: ignore
190190
return _mutmut_trampoline(object.__getattribute__(self, 'xǁAdderǁadd__mutmut_orig'), object.__getattribute__(self, 'xǁAdderǁadd__mutmut_mutants'), args, kwargs, self)
191191
\n\
192192
xǁAdderǁadd__mutmut_mutants : ClassVar[MutantDict] = { # type: ignore

0 commit comments

Comments
 (0)