Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 9, 2024

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
2 of 3 checks passed
@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