-
-
Notifications
You must be signed in to change notification settings - Fork 640
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
Implement a polished v2 MyPy experience #10131
Comments
This is not a perfect implementation yet. See #10131 for remaining TODOs. But, this gives an initial implementation to build off of. A key decision of this PR is to add MyPy to the `lint` goal, rather than a new `typecheck` goal. Users shared feedback that they prefer this, as it's neat to run all your linters in parallel. Technically, MyPy is a linter, only a supercharged one. To activate, add `pants.backend.python.lint.mypy` to `backend_packages2`. [ci skip-rust-tests] [ci skip-jvm-tests]
) Some benefits: * Runs in parallel with other linters. * We can now delete v1 MyPy. * We don't need the `type_checked` tag anymore. It's safe to run `./pants lint ::`. This means no more `mypy.py` script! This implementation is not perfect (#10131), especially with performance. [ci skip-rust-tests] [ci skip-jvm-tests]
We should probably break out the 3rdparty aspect of this and ensure that it is done by |
Since this issue mentions a polished mypy experience, can I suggest support for https://github.com/dropbox/mypy-protobuf ?
|
Great suggestion. |
MyPy only requires Python 3.5 but we have lots of code that uses Python 3.6 features which will not parse under Python 3.5. As such bump the default interpreter constraints to be compatible with both MyPy and our codebase. This will be fixed correctly as part of pantsbuild#10131. # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
MyPy only requires Python 3.5 but we have lots of code that uses Python 3.6 features which will not parse under Python 3.5. As such bump the default interpreter constraints to be compatible with both MyPy and our codebase. This will be fixed correctly as part of #10131.
The main open question is whether we want a dedicated A user may write .pyi stubs for their own code, including their own tests and their -- We need to teach dependency inference to accommodate type stubs, which means it needs to infer deps on both the original implementation and also the stubs. However, dep inference should continue to no-op if >2 implementations are detected. We could see if it's a stub by inspecting if the file address ends in -- A major downside of a dedicated Thanks to dependency inference operating at the file level—along with explicit file addresses—this isn't a big deal usually. Even if However, this breaks with explicit dependencies on the target, such as depending on -- However, updating Now that Pants always operates on a file-by-file basis, such as running tests one-file-at-a-time (batching support pending), including type stubs in a
Taking a step back, conceptually, I'm not sure that type stubs fit the bill of -- I don't think we should consider |
In general, tests shouldn't have stubs, since they shouldn't have dependents? Test-support libraries will still be libraries.
Given that a
You shouldn't need stubs in the Another consideration is that if |
You sometimes use |
I think treating I think there's no need to do anything about |
They will also be skipped to production though, which is probably not intended. So there is more than just one place to special case them: all consumers of that target type other than mypy would want to filter them. |
Could add a So basically everything acts the same as today, except for mypy, which knows to look at that field. The downside is people will have to know to use this field, instead of |
Possibly, I've been pondering it all day and talked it over with Cristian, who does have experience with type stubs, both for bindings and for first-party code. It gets a little tricky that Cristian and I agree that we do want to have autoformatters like Black and Isort run on Whatever implementation we go with, I think that we're going to want to add tests to all 6 linters, MyPy, Pytest, and setup-py that they do the right thing.
I don't follow what you mean. At least for -- On Friday, I was advocating that we don't support type stubs for your own first-party code. We only support type stubs used as bindings for third party code. I'm still not sure the right decision. Cristian has a real-world use case of preferring .pyi files for source code files. He wrote an extension of SQLAlchemy, and it's more ergonomic to have the stubs than to try to inline the hints. He's been working on seeing if inline is indeed even possible, due to some issues with Python 3.6 and inheriting -- If we do support type stubs for your own files, we have a tricky problem: how do we teach Pants dependency inference about the relationship between a The |
|
Rockin'! |
.pyi
files.No longer in scope:
The text was updated successfully, but these errors were encountered: