Replies: 1 comment
-
Generally this isn't going to be trivial since type annotations often contain forward-references to types that haven't been declared yet. So you will run into issues with runtime introspection even in modules that do have inline type annotations. The reference may never be resolved at runtime, because e.g. the symbol is imported in a This is currently almost unavoidable because CPython will not be able to resolve cyclic dependencies. (There is I don't think there's an easy way to import pyi stubs and merge them with a module at runtime. You will either need to write some static analysis code yourself that makes use of typeshed or try to integrate with something like mypy, to do it for you. It's also worth noting that the type annotations aren't a hard requirement and quite likely contain some inconsistencies with the runtime code, especially with external stubs. There are some tools like |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am experimenting with calling Python function from Haskell via C-API.
I need types to generate correspondent function stubs with Template Haskell.
I launch an embedded Python at compilation stage via
Py_Initialize
, thenPyImport_ImportModule
etc.I found
inspect.signature
function returns type for function arguments and its result if they are specified via type annotations in Python source. Also default values are returned for optional arguments, which is very helpful for inferring argument types even without annotations. Though Python library -pickle
, I am interested in, does not have such annotations at all.I found
typeshed
package contains type information forpickle.dump
.Is there an example explaining how to get this type representation after Python interpreter is started i.e. after
Py_Initialize
?Beta Was this translation helpful? Give feedback.
All reactions