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

dill.source.getsource returns partial source when called inside a decorator in a REPL #603

Open
benclifford opened this issue Jul 12, 2023 · 0 comments · May be fixed by #651
Open

dill.source.getsource returns partial source when called inside a decorator in a REPL #603

benclifford opened this issue Jul 12, 2023 · 0 comments · May be fixed by #651

Comments

@benclifford
Copy link

benclifford commented Jul 12, 2023

I noticed this behaviour - I'm able to easily work around in my case, but noting it here.

In a REPL, Python 3.11, when getsource is invoked inside a decorator function (so trying to get the source of the function that is being decorated right now), partial source is returned (rather than the whole source, or an error). This problem does not happen with the same code in a Python file executed from the command line.

>>> import demo
>>> @demo.d
... def m():
...   print("hi")
...   return 7
... 
@demo.d
def m():
  print("hi")

>>> 

but in this case, with getsource running much later (getsource is called when the decorated function is invoked), I get the full source:

>>> import demo
>>> @demo.e
... def m():
...   print("hi")
...   return 8
... 
>>> m()
@demo.e
def m():
  print("hi")
  return 8

with demo.py:

import dill.source

def d(f):
    print(dill.source.getsource(f))
    return f

def e(f):
    def wrapped():
      print(dill.source.getsource(f))
    return wrapped
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 a pull request may close this issue.

1 participant