Fix ParameterizedBenchmark in 3.8 which was broken by PEP570.

This should fix breakage of tensorflow/rel/nightly/macos/cpu_py38_nonpip

PiperOrigin-RevId: 341133149
Change-Id: I43cd8099405bf0c3b51bbc6865417acf6954f2aa
This commit is contained in:
Saurabh Saxena 2020-11-06 15:47:46 -08:00 committed by TensorFlower Gardener
parent fcb5476957
commit fc8df60449

View File

@ -65,13 +65,24 @@ def _rename_function(f, arg_num, name):
func_code.co_firstlineno, func_code.co_lnotab,
func_code.co_freevars, func_code.co_cellvars)
else:
new_code = types.CodeType(arg_num, 0, func_code.co_nlocals,
func_code.co_stacksize, func_code.co_flags,
func_code.co_code, func_code.co_consts,
func_code.co_names, func_code.co_varnames,
func_code.co_filename, name,
func_code.co_firstlineno, func_code.co_lnotab,
func_code.co_freevars, func_code.co_cellvars)
if sys.version_info > (3, 8, 0, "alpha", 3):
# Python3.8 / PEP570 added co_posonlyargcount argument to CodeType.
new_code = types.CodeType(arg_num, func_code.co_posonlyargcount,
0, func_code.co_nlocals,
func_code.co_stacksize, func_code.co_flags,
func_code.co_code, func_code.co_consts,
func_code.co_names, func_code.co_varnames,
func_code.co_filename, name,
func_code.co_firstlineno, func_code.co_lnotab,
func_code.co_freevars, func_code.co_cellvars)
else:
new_code = types.CodeType(arg_num, 0, func_code.co_nlocals,
func_code.co_stacksize, func_code.co_flags,
func_code.co_code, func_code.co_consts,
func_code.co_names, func_code.co_varnames,
func_code.co_filename, name,
func_code.co_firstlineno, func_code.co_lnotab,
func_code.co_freevars, func_code.co_cellvars)
return types.FunctionType(new_code, f.__globals__, name, f.__defaults__,
f.__closure__)