Feature Request: streamline importing python code and type annotations #298
Locked
strangemonad
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
this proposal isn't completely thought-out w.r.t. type checking but there's at least some rough thoughts
Overview
This aims to streamline the core experience of using imported python code
Dependencies
Proposal
There's 2 parts to the proposal
1. Import syntax
Allow an alternative import syntax to directly import python types. I could be convinced that this special syntax isn't even needed. For the time being though, being explicit here seems prudent.
This would be roughly equivalent to
let <ident> = Python.import_module("<module_name>")
.2. Use imported python types as type annotations
Allow type annotations to match what you'd expect when annotating python
e.g.
Motivating example
Let's use a simple example of benchmarking numpy's. In some cases you have to either thread imported python values as arguments or re-import them where you're using them.
Things I haven't thought through deeply
np.array
becomingPythonObject[<NumpyArrayPyType>]
whereNumpyArrayPyType
is the specific type. I could imagine this could even have a runtime representation by calling into the CPython API to get the PyTypeObject? This approach could also support generics as multiple parameters.NumpyArrayPyType
as having aPythonObject
upper bound.alias
or@parameter
expressions or if this warrants different semantics.Beta Was this translation helpful? Give feedback.
All reactions