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
Bug report
Bug description:
Here is the code snippet:
On Python 3.12, the output is expected:
On Python 3.13.7, the output is missing the first line
@(:On Python 3.13.9 and current
mainbranch, the output just contains the lines inside@(...):I bisected the changes:
@(first line.@(...)CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
Linux