bpo-37032: Add CodeType.replace() method (GH-13542)

This commit is contained in:
Victor Stinner 2019-05-24 23:57:23 +02:00 committed by GitHub
parent 561612d845
commit a9f05d69cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 401 additions and 33 deletions

View file

@ -619,13 +619,7 @@ class ModuleFinder:
if isinstance(consts[i], type(co)):
consts[i] = self.replace_paths_in_code(consts[i])
return types.CodeType(co.co_argcount, co.co_posonlyargcount,
co.co_kwonlyargcount, co.co_nlocals,
co.co_stacksize, co.co_flags,
co.co_code, tuple(consts), co.co_names,
co.co_varnames, new_filename, co.co_name,
co.co_firstlineno, co.co_lnotab, co.co_freevars,
co.co_cellvars)
return co.replace(co_consts=tuple(consts), co_filename=new_filename)
def test():