A year ago someone asked about adding Type Hints t...
# dev-metaflow
l
A year ago someone asked about adding Type Hints to Metaflow. Is this still out of the question due to Python 2.7 support? If 2.7 support is dropped: could we start adding Type Annotations? If 2.7 support is still active: have we considered writing stubs? AKA
.pyi
files? I've not authored one of these myself, but I believe these allow you to define type hints in a separate file to the source code files, thus preserving Python 2.7 compatibility, but adding much desired autocompletion/intellisense to editors. Original thread by @cold-airport-8333 and @narrow-lion-2703 /@User linked in thread.
1
Resources: • Section of RealPython article on stub files: https://realpython.com/python-type-checking/#adding-stubs • Mypy wiki page on stub files: https://github.com/python/mypy/wiki/Creating-Stubs-For-Python-Modules • Brief intro to stub files on StackOverflow. This answer specifically calls out Python 2-3 compatibility as a reason to use stub files: https://stackoverflow.com/questions/59051631/what-is-the-use-of-stub-files-pyi-in-python
d
So python 2.7 is no longer considered a requirement (we are currently on 3.5+ — yes, still old but progress 🙂 ). In terms of type hints, I actually have a PR out for it: https://github.com/Netflix/metaflow/pull/1158/files and there is something else that I have not yet put out that would generate the .pyi files as well (reason for that is the extension mechanism that metaflow supports which confuses traditional static parsers so this generates .pyi dynamically). I have several things going on at the same time but I’ll try to make more progress on this if there is more interest on it.
@victorious-lawyer-58417 and @square-wire-39606 for viz.
l
@dry-beach-38304 Oh awesome! I read through it and made some basic comments. Thanks for proposing these changes 😎
d
awesome! Thanks. I’ll try to get back to it and get something out in a PR form (more fully) shortly.
and something like this will make it in. It’s been requested a few times and it does make sense.
🤞 1
the only thing was trying to make it easy for users to use but from what I can tell stub files are kind of read on an editor-by-editor basis (ie: you typically have to tell it to look somewhere). I haven’t tested including it directly in the wheel. Do you have experience/knowledge in this area? I can then try it out to make it as simple as possible for users.
l
I don't sadly. Do you think the experiment is worth running, though? Like, is it worth effort to investigate adding
.pyi
files to a Metaflow wheel instead of the inline type hints in your PR?
d
so the type hints provide quite a bit already but the pyi add additional things because of some of the tricks/quirks of metaflow (for example decorators). I should actually push out the full PR. I need a bit of time to clean it up then I’ll push it out and you can see what I mean by it.
l
Oh, I didn't think about that. Yeah, decorators would be hard to annotate. What does "push out" mean? I could imagine this PR getting accepted as an incremental step towards better hinting. And then
pyi
files could be added later. If the two conflict, these types could be removed at that point. I don't imagine there would be issues with backwards compatibility if the in-line hints were added then taken out later.
d
there shouldn’t be. I meant that I wanted to make sure the whole thing worked first 🙂. But yes, most likely the type hints would come first (this PR) and then the rest in a separate PR.
❤️ 1