-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Include py.typed file in distribution (PEP 561) #7073
Conversation
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.
Thanks for catching this Talley! Seems obvious that we want to include this change.
Though, I can't seem to reproduce this with PyCharm on my side; behavior is identical with and without py.typed
. And PyCharm finds the docstring without the file. Which IDE are you using, a vscode-based one?
Yep, vscode |
If I recall correctly, pycharm actually does dynamic imports for a number of things? |
Thanks @tlambert03. :) |
I was used to a single: Now I need a "# type: ignore" for every still untyped function I use to make the mypy check happy. |
You can use the mypy configuration to batch ignore, or selectively ignore specific errors (or all errors): example overriding specific modules here: https://mypy.readthedocs.io/en/stable/config_file.html#example-pyproject-toml |
I was surprised that I would recommend, if possible, that you only add a |
for a little added context: So, in order to tell IDEs what scikit-image has available, two options were presented (#6435 and #6429), and a variant of #6435 was merged in #6577, using pyi stubs to indicate to IDEs what modules & functions scikit-image had to offer. However, in order for static type checkers to use these static hints, you must include a py.typed file (as per PEP 561). My understanding of the implications of py.typed from PEP 561 is not to indicate some critical mass or coverage of typed functions in a package, but simply to indicate to type checkers that they should search this package for stubs, as opposed to a third party stubs package (or typeshed) which was the historical/legacy way that many packages incrementally offered types. Users who wish to use mypy with strict setting (I'm definitely a fan) often do need to add a bit of configuration for partially typed dependencies. (and I feel like having to add I don't particularly have a preference here, i leave it to the maintainers of scikit-image to decide... but if you would vote for the removal of py.typed, then I think you also need to suggest how you would deal with the inability of IDEs to detect anything in scikit-image given the use of lazy imports. |
The problem is that the way the suppressions work, you can't add a blanket ignore for problems in a third party library (at least I could not get this to work) because the calls to For example, I tried: [[tool.mypy.overrides]]
module = "skimage"
disallow_untyped_calls = false But this does not suppress
I would be happy to be proven wrong if there is a Mypy configuration that can suppress only |
my apologies, this feature was merged in mypy a couple days after the most release release in August: python/mypy#15845 so, it will be available soon. but until then, you're correct that's it doesn't appear possible to enforce strict typing for your own library, while using scikit-image without local ignores. I don't have too much more to add, but will just re-iterate that this is a genuinely tricky problem.
cheers! |
I personally find type-hinting very useful, both in prototyping and proper development scenarios. So, in my mind, we should definitely go that path. |
Thanks for the reference! That certainly will limit the impact of this change and allow users to suppress this particular issue. I agree that after the next Mypy release, the negative impacts of this PR will not be nearly as severe. |
@johnthagen, sorry for the py.typed related annoyance from our side. We currently have a grant that also entails typing our API. It's a big effort and we are also trying to revise our API in the process but you can follow along in
From skimming the discussion above, our best bet seems to be to continue work on that and leave the py.typed be. |
As of Mypy 1.6.1, you can now suppress only the untyped call errors in [tool.mypy]
strict = true
untyped_calls_exclude = [
"skimage"
] |
needed in order for the .pyi files to be useful: see: scikit-image/scikit-image#7073
needed in order for the .pyi files to be useful: see: scikit-image/scikit-image#7073
needed in order for the .pyi files to be useful: see: scikit-image/scikit-image#7073
This MR does not add any new features. It just has minor fixes ported from scikit-image 0.22. Most changed lines are from moving additional modules to use `__init__.pyi` files as for upstream scikit-image. Regarding introduction of `py.typed`, see [discussion on the scikit-image repo](scikit-image/scikit-image#7073). The TLDR version is that it enables VS CODE (and potentially other IDEs) to use the `.pyi` files for intellisense capabilities. Those using mypy with strict type checking, may have to add an exclusion like the following to disable warnings about most of the cuCIM API which does not currently use type hints: ```toml [tool.mypy] strict = true untyped_calls_exclude = [ "cucim" ] ``` Authors: - Gregory Lee (https://github.com/grlee77) - https://github.com/jakirkham Approvers: - Gigon Bae (https://github.com/gigony) - https://github.com/jakirkham - Ray Douglass (https://github.com/raydouglass) URL: #670
Description
In order for the
.pyi
files to be useful, scikit-image needs to include apy.typed
file in top level module of the distribution.See PEP 561 and the mypy documentation for more information.
currently, when using scikit-image in an IDE, you get:
if you drop
py.typed
file in the skimage folder of site-packages you get: