检查 getsource 未响应类上的注释

问题描述 投票:0回答:0

例如,我有一个 Python 课程:

def dec(clz):
  return clz

@dec
class Test:
  pass 

当我在python 3.8中使用

insepct.getsource(Test)
时,源代码没有
@dec
但是当我使用 python 3.10 时,源代码将包含
@dec

有什么信息说明这种差异是从哪里来的吗? 如果我必须支持 3.8 python,我需要使用什么函数来获取注释和源代码?

谢谢

python decorator inspect
© www.soinside.com 2019 - 2024. All rights reserved.