File tree Expand file tree Collapse file tree 1 file changed +3
-7
lines changed
Expand file tree Collapse file tree 1 file changed +3
-7
lines changed Original file line number Diff line number Diff line change @@ -107,13 +107,9 @@ def rename(f):
107107 # https://docs.python.org/3/library/types.html#types.CodeType
108108 # https://docs.python.org/3/library/inspect.html#types-and-members
109109 if version_info >= (3 , 8 , 0 ): # Python 3.8+: positional-only parameters
110- f .__code__ = CodeType (co .co_argcount , co .co_posonlyargcount , co .co_kwonlyargcount ,
111- co .co_nlocals , co .co_stacksize , co .co_flags ,
112- co .co_code , co .co_consts , co .co_names ,
113- co .co_varnames , co .co_filename ,
114- name ,
115- co .co_firstlineno , co .co_lnotab , co .co_freevars ,
116- co .co_cellvars )
110+ # In Python 3.8+, `CodeType` has the convenient `replace()` method to functionally update it.
111+ # In Python 3.10, we must actually use it to avoid losing the line number info.
112+ f .__code__ = f .__code__ .replace (co_name = name )
117113 else :
118114 f .__code__ = CodeType (co .co_argcount , co .co_kwonlyargcount ,
119115 co .co_nlocals , co .co_stacksize , co .co_flags ,
You can’t perform that action at this time.
0 commit comments