##// END OF EJS Templates
Merge pull request #13535 from fabioz/fix_cofirstlineno...
Matthias Bussonnier -
r27536:cda6c4ca merge
parent child Browse files
Show More
@@ -15,6 +15,7 b' import abc'
15 import ast
15 import ast
16 import atexit
16 import atexit
17 import builtins as builtin_mod
17 import builtins as builtin_mod
18 import dis
18 import functools
19 import functools
19 import inspect
20 import inspect
20 import os
21 import os
@@ -3139,6 +3140,29 b' class InteractiveShell(SingletonConfigurable):'
3139 ast.fix_missing_locations(node)
3140 ast.fix_missing_locations(node)
3140 return node
3141 return node
3141
3142
3143 def _update_code_co_name(self, code):
3144 """Python 3.10 changed the behaviour so that whenever a code object
3145 is assembled in the compile(ast) the co_firstlineno would be == 1.
3146
3147 This makes pydevd/debugpy think that all cells invoked are the same
3148 since it caches information based on (co_firstlineno, co_name, co_filename).
3149
3150 Given that, this function changes the code 'co_name' to be unique
3151 based on the first real lineno of the code (which also has a nice
3152 side effect of customizing the name so that it's not always <module>).
3153
3154 See: https://github.com/ipython/ipykernel/issues/841
3155 """
3156 if not hasattr(code, "replace"):
3157 # It may not be available on older versions of Python (only
3158 # available for 3.8 onwards).
3159 return code
3160 try:
3161 first_real_line = next(dis.findlinestarts(code))[1]
3162 except StopIteration:
3163 return code
3164 return code.replace(co_name="<cell line: %s>" % (first_real_line,))
3165
3142 async def run_ast_nodes(
3166 async def run_ast_nodes(
3143 self,
3167 self,
3144 nodelist: ListType[stmt],
3168 nodelist: ListType[stmt],
@@ -3237,6 +3261,7 b' class InteractiveShell(SingletonConfigurable):'
3237 else 0x0
3261 else 0x0
3238 ):
3262 ):
3239 code = compiler(mod, cell_name, mode)
3263 code = compiler(mod, cell_name, mode)
3264 code = self._update_code_co_name(code)
3240 asy = compare(code)
3265 asy = compare(code)
3241 if await self.run_code(code, result, async_=asy):
3266 if await self.run_code(code, result, async_=asy):
3242 return True
3267 return True
General Comments 0
You need to be logged in to leave comments. Login now