-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
modulefinder uses wrong CodeType signature in .replace_paths_in_code() #65906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Here's the code: def replace_paths_in_code(self, co):
...
return types.CodeType(co.co_argcount, 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) Compare this to the code_new() C API doc string (and code): code(argcount, kwonlyargcount, nlocals, stacksize, flags, codestring,\n\
constants, names, varnames, filename, name, firstlineno,\n\
lnotab[, freevars[, cellvars]]) The kwonlyargcount is missing in the call used in .replace_paths_in_code(). The bug surfaces when trying to use the "-r" option of the freeze.py tool: Traceback (most recent call last):
File "freeze.py", line 504, in <module>
main()
File "freeze.py", line 357, in main
mf.import_hook(mod)
File "/home/lemburg/egenix/projects/PyRun/tmp-3.4-ucs2/lib/python3.4/modulefinder.py", line 123, in import_hook
q, tail = self.find_head_package(parent, name)
File "/home/lemburg/egenix/projects/PyRun/tmp-3.4-ucs2/lib/python3.4/modulefinder.py", line 179, in find_head_package
q = self.import_module(head, qname, parent)
File "/home/lemburg/egenix/projects/PyRun/tmp-3.4-ucs2/lib/python3.4/modulefinder.py", line 272, in import_module
m = self.load_module(fqname, fp, pathname, stuff)
File "/home/lemburg/egenix/projects/PyRun/tmp-3.4-ucs2/lib/python3.4/modulefinder.py", line 303, in load_module
co = self.replace_paths_in_code(co)
File "/home/lemburg/egenix/projects/PyRun/tmp-3.4-ucs2/lib/python3.4/modulefinder.py", line 569, in replace_paths_in_code
consts[i] = self.replace_paths_in_code(consts[i])
File "/home/lemburg/egenix/projects/PyRun/tmp-3.4-ucs2/lib/python3.4/modulefinder.py", line 575, in replace_paths_in_code
co.co_freevars, co.co_cellvars)
TypeError: an integer is required (got type bytes) |
The fix is easy. Simply change the call to: return types.CodeType(co.co_argcount, 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) (ie. add the missing argument) |
Here's a patch with a test. |
New changeset 59921d2f023c by Berker Peksag in branch '3.4': New changeset 4b6798e74dcf by Berker Peksag in branch 'default': |
New changeset f8deaac44ed4 by Berker Peksag in branch '3.4': New changeset e66c387da81b by Berker Peksag in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: