From 4e7e100dc9e6bb6a495169108199b4eee6bddfcd Mon Sep 17 00:00:00 2001 From: JD Smith <93749+jdtsmith@users.noreply.github.com> Date: Mon, 28 Mar 2022 12:05:26 -0400 Subject: [PATCH] Revert "Set co_name for cells run line by line. Fixes https://github.com/ipython/ipykernel/issues/841" This reverts commit d11e987f174a15f1640f8006c86f58d884c3faa4. --- IPython/core/interactiveshell.py | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 790a75e7d4e..96e7cd1dd4b 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -15,7 +15,6 @@ import ast import atexit import builtins as builtin_mod -import dis import functools import inspect import os @@ -3183,29 +3182,6 @@ def transform_ast(self, node): ast.fix_missing_locations(node) return node - def _update_code_co_name(self, code): - """Python 3.10 changed the behaviour so that whenever a code object - is assembled in the compile(ast) the co_firstlineno would be == 1. - - This makes pydevd/debugpy think that all cells invoked are the same - since it caches information based on (co_firstlineno, co_name, co_filename). - - Given that, this function changes the code 'co_name' to be unique - based on the first real lineno of the code (which also has a nice - side effect of customizing the name so that it's not always ). - - See: https://github.com/ipython/ipykernel/issues/841 - """ - if not hasattr(code, "replace"): - # It may not be available on older versions of Python (only - # available for 3.8 onwards). - return code - try: - first_real_line = next(dis.findlinestarts(code))[1] - except StopIteration: - return code - return code.replace(co_name="" % (first_real_line,)) - async def run_ast_nodes( self, nodelist: ListType[stmt], @@ -3304,7 +3280,6 @@ def compare(code): else 0x0 ): code = compiler(mod, cell_name, mode) - code = self._update_code_co_name(code) asy = compare(code) if await self.run_code(code, result, async_=asy): return True