Skip to content

fix fencepost error when getting source inside decorator in interpreter (fixes #603)#651

Merged
mmckerns merged 1 commit intouqfoundation:masterfrom
timkpaine:tkp/fencepost
Jul 9, 2024
Merged

fix fencepost error when getting source inside decorator in interpreter (fixes #603)#651
mmckerns merged 1 commit intouqfoundation:masterfrom
timkpaine:tkp/fencepost

Conversation

@timkpaine
Copy link
Contributor

@timkpaine timkpaine commented Apr 2, 2024

Summary

I believe this fixes an off-by-one error for functions defined in the interpreter.

I am not sure how to test this as it only runs when directly instantiated in an interpreter.
Fixes #603.

Inline test:

from dill.source import getsource

def my_decorator(foo):
    s = getsource(foo)
    print(s)
    assert s.endswith("return 1\n")

@my_decorator
def foo():
  return 1

Before

@my_decorator
def foo():

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in my_decorator
AssertionError

After

@my_decorator
def foo():
    return 1
>>>

Please let me know any suggestions for how to implement a test for this!

Checklist

Documentation and Tests

  • Added relevant tests that run with python tests/__main__.py, and pass.
  • Added relevant documentation that builds in sphinx without error.
  • Added new features that are documented with examples.
  • Artifacts produced with the main branch work as expected under this PR.

Release Management

  • Added "Fixes #NNN" in the PR body, referencing the issue (#NNN) it closes.
  • Added a comment to issue #NNN, linking back to this PR.
  • Added rationale for any breakage of backwards compatibility.
  • Requested a review.

@mmckerns mmckerns added this to the dill-0.3.9 milestone Jul 9, 2024
@mmckerns mmckerns added the bugfix label Jul 9, 2024
@mmckerns mmckerns merged commit a9d136b into uqfoundation:master Jul 9, 2024
@mmckerns
Copy link
Member

mmckerns commented Jul 9, 2024

thanks for the patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants