metacraft-labs / py2nim

A Python-to-Nim transpiler
MIT License
135 stars 8 forks source link

Make use of Python 3 type annotations #15

Open wizzardx opened 6 years ago

wizzardx commented 6 years ago

Perhaps you can borrow logic used by mypy (with it's strictest options, as well as things like typed-ast usage, type inference algorithm, etc), to be able to exactly determine all types, rather than (always) needing to execute the code to determine types?

I think mypy also includes options to export a list of all the types and inferred types, which could be used as an input to py2nim.

I'm a big fan of mypy and static type annotations.

alehander92 commented 6 years ago

Mypy support would be very useful and it wouldn't be hard to add basic support for mypy annotations. We just need to convert them to our type format.

However mypy is still not as universal in python ecosystems as typescript info in js. Many smaller libs for which py2nim is required don't have mypy definitions. That's why it hasn't been a big priority: it would be cool to support it, but if we already have runtime inference, it's not such a big deal.

Also, we wanted to have more power on what exactly we trace: we trace local variables, we annotate ast nodes with the resolved calls during runtime, we'll eventually trace dicts elements etc. That's why we didn't reuse pyannotate (which is more limited for our usecase).