-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[WIP] Annotations to help mypy #3181
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
Conversation
pymc3/data.py
Outdated
@@ -7,6 +7,7 @@ | |||
import pymc3 as pm | |||
import theano.tensor as tt | |||
import theano | |||
from typing import Dict, List |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this available in Python 2 as well?
Are you going to add type hints elsewhere too? |
Just want to pitch in my two cents: adding type annotations would greatly improve the quality of life for the dev team, especially for the many (unfortunately) undocumented functions in the PyMC3 backend. It's also probably a good idea to add For now we can add them in backwards-compatible format, but when we sunset support for py2 next year, it should be fairly painless to convert all the annotations to the py3 format. |
That would be my key question, should we bother with mypy if we could just use python 3 annotations fairly soon? Master could already start becoming python 3, technically, depending on when we do the next release. |
I could be wrong, but my understanding was that the syntax is python 3.6+, but that one still needs an external tool like mypy to do the static analysis.
But I'm FAR from an expert on the python ecosystem -- I just got involved to use pymc3, and I'm still learning, so you tell me.
…Sent from my iPhone
On Sep 3, 2018, at 08:48, Thomas Wiecki ***@***.***> wrote:
For now we can add them in backwards-compatible format, but when we sunset support for py2 next year, it should be fairly painless to convert all the annotations to the py3 format.
That would be my key question, should we bother with mypy if we could just use python 3 annotations fairly soon? Master could already start becoming python 3, technically, depending on when we do the next release.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
You still need an external tool, but you can have the annotation directly in code. |
The commits I have here are pretty much all directly in the code, except I used the old way of type-hinting data properties of classes, instead of the 3.6+ way. Those would be easy to change later. I see that I caused a problem by not commenting to hide the |
If this fixes travis, and the mods are ok, probably they should be squash-merged. |
I would hold off on type annotations until they become more standard with Py3.7 and beyond. For now, if we have undocumented functions, let’s spend the time to document them. |
@fonnesbeck The only reason I would disagree with this is that the PyMC3 code base seems to have a fairly large number of type errors in it, as witness my #3179 I don't believe that bugs like that -- which arise when code makes incorrect assumptions about the return value of the same method implemented in multiple different classes -- is readily detected by just fixing documentation. For that matter, I wouldn't say that this is an either/or decision: I don't know enough to write good documentation for PyMC3, but I can provide some type hinting, and maybe through type hinting provide useful bug reports or patches. P.S. My primary interest is in providing type stubs, in order to help me when I am writing code that uses PyMC3, and I think that providing those stubs is generally useful (perhaps more useful than hinting the code itself). |
@twiecki I'm trying to make sure that any hinting does not conflict with Python 2.7. |
I’m not at all opposed to adding type annotations/hints, it’s a matter of when and how it happens. As Thomas suggests, it should probably happen project-wide when it does. I can make sure that the issue is discussed at an upcoming project meeting to gauge the support and timing. |
BTW, if there are egregious cases of missing documentation, please raise an issue(s). They will be taken care of. |
@fonnesbeck For what it's worth, the biggest problem for me as a user has been inconsistency in protocols (I mean "protocols" in the common sense, not in the Python language sense). For example, in my bug report there's an assumption about what the |
OK, I'm stumped by the errors in Travis. I have tried to follow the instructions I've found to tell pylinter to ignore the unused imports from |
@rpgoldman, now that we dropped python 2 support and testing, would a rebase pass on Travis? |
Eventually we may want to upgrade these type hints to the python3 based syntax (https://docs.python.org/3/library/typing.html), rather than the py27-compatible syntax. The py3k syntax also seems to behave better with linters etc. |
I will check -- I haven't updated these in a while -- was just on hold. I'll get back to this sometime this week. |
In case folks didn't understand, what I mean is that we could switch from
to
|
Yeah I think it'd be great to make use of that python 3 feature now that we can. I'll close this but feel free to keep posting. |
@twiecki Would it be reasonable to reopen this, and retitle it as a WIP merge request? Then the mainline of the project can track as I develop more annotations, while it's still too early to be merged. It looks like when you close this, the Travis checking is removed. If we want to keep this closed, can you clue me in about how I can put Travis checks in place on my branch? |
Sure, if you prefer to keep developing on this PR. |
Looks like switching to Python 3 exclusively solved the problems I was having with test failures. That's nice! How do the developers feel about type annotations in PyMC3 itself? |
I don't have much experience with
Do you know if these 4 sentences are true, or would you rewrite them or add caveats? If they were true, I would suggest we start allowing type annotations, see how helpful it is for devs and users, and then make a more focused push if they were, indeed, very helpful. |
I think that's mostly true. I'd add a couple of points:
If there's interest, it might help to introduce, at least for end users, some explicit protocol notions. For example, IIRC |
I'd be very interested in seeing a PR that shows this. probably good to start small |
Closing due to inactivity. |
Added comments to make mypy ignore decorated properties it doesn't understand.
Added type declaration for RNG in backwards-compatible form.