-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type information to API #368
Comments
I would be totally happy to add type hints, beginning at least with the public API. In fact, most of the public API defines its expected types already using the magic Sphinx docstrings, so we're not that far from being able to do it. However, you're right that the Python 2 compat requirement makes this more tricky. What we need is something that can satisfy the following rules:
I'm not yet sure if there are any type annotation systems that cover all those bases. We should take a look. |
I have yet to try it in anger, but I think (based on a few conversations at PyCon) that MyPy would get us part of the way. I don’t think it can do the Sphinx-extraction (yet, I know the idea’s been floated), but I think it can do the other stuff. |
Yeah, so I assume that mypy would be the type checker to use. The biggest issue is: how do we convince Sphinx to use the types so that we don't have to duplicate them. |
I'm somewhat nervously considering the possibility that "write a Sphinx plugin" may be the actual solution to this problem, and wow do I not want that to be the solution. |
ponders
I thought the same thing, but I also think “write a Sphinx plugin” might be a fun and useful challenge. (I also got about two hours of sleep last night, so my judgement may be a little suspect.) I’ve never written a Sphinx plugin, so I have no idea how hard it would be; I’ll look at it properly when I get some free time at the weekend. |
So I know there is a Sphinx plugin to get types out of function annotations, so such a thing is clearly possible, in the abstract sense. |
@jonparrott has mentioned that he's worked on something related that might be adaptable to our use-case. |
In summary - for Python 2:
I ended up tabling (3) for the time being, and just fixing (2). That's what So - this might be useful to you guys in a few ways:
|
fixes python-hyper#368 --wip-- [skip ci] --wip-- [skip ci] --wip-- [skip ci] --wip-- [skip ci] fix None bugs --wip-- [skip ci] --wip-- [skip ci]
Due to small type inconsistencies one might fall into a trap where incompatible objects might still be auto-mangled into something that fits, but isn't right. One example of such a case just happened: ref #367. The docs clearly stated one thing, but passing in something completely different still worked, until the the last release. The public API was still the same, but the underlying implementation changed.
How do you feel about adding type checks, type hints, or similar annotations to help the user avoid such mistakes?
E.g.:
http://mypy-lang.org/
https://www.python.org/dev/peps/pep-0484/
https://docs.python.org/3/library/typing.html
and similar
I think, since python-hyper aims for Python 2 support as well, this might be a bit more difficult.
The text was updated successfully, but these errors were encountered: