-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Closed as duplicate of#139838
Closed as duplicate of#139838
Copy link
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Here is the code snippet:
import inspect
import sys
def decorator_builder(**kwargs):
class DecoratorChain:
def __init__(self, **kw):
self.kwargs = kw
def with_option(self, value):
self.kwargs["option"] = value
return self
def __call__(self, fn):
return fn
return DecoratorChain(**kwargs)
@(
decorator_builder(
version=1,
name="example",
).with_option("test")
)
def function():
return "hello"
print("Source is:")
print(inspect.getsource(function))On Python 3.12, the output is expected:
Source is:
@(
decorator_builder(
version=1,
name="example",
).with_option("test")
)
def function():
return "hello"
On Python 3.13.7, the output is missing the first line @(:
Source is:
decorator_builder(
version=1,
name="example",
).with_option("test")
)
def function():
return "hello"
On Python 3.13.9 and current main branch, the output just contains the lines inside @(...):
Source is:
decorator_builder(
version=1,
name="example",
).with_option("test")
I bisected the changes:
- inspect.getsource does not work for a class-defined code object #116987 resulted in the missing
@(first line. - gh-137477: Fix inspect.getblock() for generator expressions #137488 (and the [3.13] gh-137477: Fix inspect.getblock() for generator expressions (GH-137488) #137995 backport) resulted in containing only the lines inside
@(...)
CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error