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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

timkpaine
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dill.source.getsource returns partial source when called inside a decorator in a REPL
1 participant