10 Jan
2025
10 Jan
'25
1:40 a.m.
This snippet appears to duplicate a code object in the online python interpreter i tried: import types, inspect f = some_function code_copy = types.CodeType(*[getattr(f.__code__, 'co_'+p.replace('string','').replace('ant','')) for p in inspect.signature(types.CodeType).parameters]) it looks like the CodeType parameters might change across python versions or might not not sure two of them don't match the property names, 'co_code' matches with 'codestring' and 'co_consts' matches with 'constants'. so the two .replace calls perform that matching in a hacky 1-liner