-
-
Notifications
You must be signed in to change notification settings - Fork 189
Closed
Labels
Milestone
Description
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
Reactions are currently unavailable