Skip to content

Commit

Permalink
Update monkeypatch to fix (many) line numbers being off due to decora…
Browse files Browse the repository at this point in the history
…tors (#86)

* Improve jurigged line number monkeypatch

* Increment version
  • Loading branch information
JamesHutchison authored Apr 18, 2024
1 parent 3fb392c commit 6ee3cc3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ line-length = 98

[tool.poetry]
name = "pytest-hot-reloading"
version = "0.1.0-alpha.17"
version = "0.1.0-alpha.18"
description = ""
authors = ["James Hutchison <[email protected]>"]
readme = "README.md"
Expand Down
10 changes: 3 additions & 7 deletions pytest_hot_reloading/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,11 @@ def apply_assertion_rewrite(self, ast_func, glb):
return ast_func

def stash(self, lineno=1, col_offset=0):
# monkeypatch: There's an off-by-one bug coming from somewhere in jurigged.
# This affects replaced functions. When line numbers are wrong
# the debugger and inspection logic doesn't work as expected.
# monkeypatch to fix line numbers from decorators: See https://github.com/breuleux/jurigged/issues/29
if not isinstance(self.parent, OrigFunctionDefinition):
co = self.get_object()
if co and (delta := lineno - co.co_firstlineno):
delta -= 1 # fix off-by-one
if delta != 0:
self.recode(jurigged_utils.shift_lineno(co, delta), use_cache=False)
if co and (delta := lineno - self.node.extent.lineno):
self.recode(jurigged_utils.shift_lineno(co, delta), use_cache=False)

return super(OrigFunctionDefinition, self).stash(lineno, col_offset)

Expand Down

0 comments on commit 6ee3cc3

Please sign in to comment.