Reputation: 596
Is there a Python type hint/annotation for code objects (as returned by compile
on source code strings, or the result of calling the __code__
attribute on a method)? I have a method which accepts a single code object argument, and I want to annotate it appropriately using appropriately the typing
library.
>>> 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)
>>> {}
Upvotes: 3
Views: 637
Reputation: 96286
Yeah, it is available in the module types
:
from types import CodeType
code: CodeType = compile('x = 1', 'test', 'single')
Upvotes: 4