【发布时间】:2020-06-06 21:31:45
【问题描述】:
是否有代码对象的 Python 类型提示/注释(由源代码字符串上的 compile 返回,或者在方法上调用 __code__ 属性的结果)?我有一个接受单个代码对象参数的方法,我想适当地使用 typing 库对其进行注释。
>>> c = compile('x = 1', 'test', 'single')
>>> <code object <module> at 0x1075f8660, file "test", line 1>
>>> c
>>> code
>>> type(c)
>>> type
>>> typing.get_type_hints(c)
>>> {}
【问题讨论】:
标签: python python-3.x types type-hinting python-typing