Skip to content

Commit

Permalink
Revert "Set co_name for cells run line by line. Fixes ipython/ipykern…
Browse files Browse the repository at this point in the history
…el#841"

This reverts commit d11e987.
  • Loading branch information
jdtsmith committed Mar 28, 2022
1 parent a1f716e commit 4e7e100
Showing 1 changed file with 0 additions and 25 deletions.
25 changes: 0 additions & 25 deletions IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import ast
import atexit
import builtins as builtin_mod
import dis
import functools
import inspect
import os
Expand Down Expand Up @@ -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 <module>).
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="<cell line: %s>" % (first_real_line,))

async def run_ast_nodes(
self,
nodelist: ListType[stmt],
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4e7e100

Please sign in to comment.