Skip to content

Commit 0a0d1da

Browse files
committed
Issue #21707: Add missing kwonlyargcount argument to ModuleFinder.replace_paths_in_code().
1 parent 344f831 commit 0a0d1da

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

Lib/modulefinder.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,12 @@ def replace_paths_in_code(self, co):
568568
if isinstance(consts[i], type(co)):
569569
consts[i] = self.replace_paths_in_code(consts[i])
570570

571-
return types.CodeType(co.co_argcount, co.co_nlocals, co.co_stacksize,
572-
co.co_flags, co.co_code, tuple(consts), co.co_names,
573-
co.co_varnames, new_filename, co.co_name,
574-
co.co_firstlineno, co.co_lnotab,
575-
co.co_freevars, co.co_cellvars)
571+
return types.CodeType(co.co_argcount, co.co_kwonlyargcount,
572+
co.co_nlocals, co.co_stacksize, co.co_flags,
573+
co.co_code, tuple(consts), co.co_names,
574+
co.co_varnames, new_filename, co.co_name,
575+
co.co_firstlineno, co.co_lnotab, co.co_freevars,
576+
co.co_cellvars)
576577

577578

578579
def test():

Lib/test/test_modulefinder.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,12 @@ def create_package(source):
245245

246246

247247
class ModuleFinderTest(unittest.TestCase):
248-
def _do_test(self, info, report=False):
248+
def _do_test(self, info, report=False, debug=0, replace_paths=[]):
249249
import_this, modules, missing, maybe_missing, source = info
250250
create_package(source)
251251
try:
252-
mf = modulefinder.ModuleFinder(path=TEST_PATH)
252+
mf = modulefinder.ModuleFinder(path=TEST_PATH, debug=debug,
253+
replace_paths=replace_paths)
253254
mf.import_hook(import_this)
254255
if report:
255256
mf.report()
@@ -308,9 +309,16 @@ def test_bytecode(self):
308309
os.remove(source_path)
309310
self._do_test(bytecode_test)
310311

312+
def test_replace_paths(self):
313+
old_path = os.path.join(TEST_DIR, 'a', 'module.py')
314+
new_path = os.path.join(TEST_DIR, 'a', 'spam.py')
315+
with support.captured_stdout() as output:
316+
self._do_test(maybe_test, debug=2,
317+
replace_paths=[(old_path, new_path)])
318+
output = output.getvalue()
319+
expected = "co_filename '%s' changed to '%s'" % (old_path, new_path)
320+
self.assertIn(expected, output)
311321

312-
def test_main():
313-
support.run_unittest(ModuleFinderTest)
314322

315323
if __name__ == "__main__":
316324
unittest.main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Core and Builtins
2727
Library
2828
-------
2929

30+
- Issue #21707: Add missing kwonlyargcount argument to
31+
ModuleFinder.replace_paths_in_code().
32+
3033
- Issue #20639: calling Path.with_suffix('') allows removing the suffix
3134
again. Patch by July Tikhonov.
3235

0 commit comments

Comments
 (0)