-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Should we accept new thirdparty stubs? #2440
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
Comments
Agreed. Though I think we could make (carefully considered) exceptions for commonly used packages of low complexity where the upstream maintainers aren't interested in putting out stubs (but do allow us to put them in typeshed). Packages that look like their stubs would require significant work to create or keep up to date should not be accepted into typeshed. Nor should packages without a large user base. |
Makes sense. For example, it makes sense to have stubs for the packaging infrastructure in typeshed. The same is true for backports of stdlib packages. |
I also agree. I like your "review service" idea; here's a few other things that could perhaps be helpful:
|
I fully agree, the PEP is clear we want to decentralize typed packages so that it scales better :) I've already started offering help to several early adopters (numpy, attrs, hypothesis, and now typed-django), so if we want to formalize that process, I am all for it. I don't have a strong opinion on providing a listing of known third-party stub packages. It will certainly help discoverability, but will likely grow unwieldy over time. As for tooling, I have a few things I am hoping to accomplish:
Also, I created https://github.com/ethanhs/pep-561 which may be a good place to discuss PEP 561 specific issues. |
Please have a look at PR #2441, were I try to reword our contributing guidelines in regards to third party stubs. |
Here is a list of issues and pull requests for new third party libraries. I suggest to close most with an explanation:
|
I like the idea of decentralizing things. Another example is https://github.com/dropbox/sqlalchemy-stubs, which is already fully functional PEP 561 package. |
Btw https://github.com/dropbox/sqlalchemy-stubs is also a nice example of how mypy test framework can be used to easily add tests/CI for a stub package. |
In my opinion as a mypy user, this will not be a good move at this time. Here is how I order the methods of third party stubs distribution by preference:
I think (1) is uncontroversial. The I prefer (2) over (3) mainly because a separate package adds a dependency that I would otherwise not have. This means that I have to find out that it exists (not bundled with mypy); I have to trust the stubs' author; I have to keep the package updated; it can be abandoned in which case I need to fork or find a replacement; if I find a problem with the stubs and want to contribute a fix, the experience can be highly variable (compared to typeshed), and so I and others are less likely to do so. Typescript should be mentioned as a point of comparison. I'd say they are using approach "2⅓" (see DefinitelyTyped). They cannot have a single "typeshed" package because it would be way too big (hopefully typeshed will have this problem too one day), and would not allow to version stubs separately. So what they do is have a single centrally-managed repository, but package each stub under a discoverable, predictable, centrally managed namespace A note about huge projects like https://github.com/dropbox/sqlalchemy-stubs and https://github.com/TypedDjango/django-stubs. I think it makes a lot of sense to develop them in a separate repository. But once they are production-ready I would still like to see them merged upstream, or absent that, to typeshed. |
Also, I think the infrastructure we have for running mypy at Dropbox
strongly favors typeshed. (To the extent that we've special-cased the
sqlalchemy and numpy stubs in a few places.) If the trend away from
typeshed continues we can adapt our infrastructure to it, but I haven't
looked into the required effort, as (apart from those two) it hasn't come
up yet.
The point that decentralized infrastructure means that stub maintainers
could walk away and it would be somewhat difficult to transfer maintenance
to a new volunteer is also well taken.
|
All in all, I basically agree with most points made by @bluetech. Here is some reasoning:
I think that we should try to learn from DefinitelyTyped -- they have ~20x the number of commits compared to typeshed, so their model appears to scale well. Here are some things that I was quickly able to learn and that we might want to adopt in some form:
Packaging stubs seems like a problem for us. We could have a single monolithic typeshed package as we currently have, but this approach has issues:
Maybe we could somehow automatically generate a separate PyPI package for each new contributed package stub? Or we could have a script that makes this easy to do, even it requires some manual work. We could automatically generate a version number from the last modified date. There is also the issues of needing to ask for permission from the package maintainers. This creates some friction. We could work around this by proactively asking for permission from the owners of the top 500 most popular packages on PyPI, for example, and making that list prominently visible somewhere. |
Additional thoughts:
|
A few points:
That said, I agree that the DefinitelyTyped model seems quite successful. I especially like the predictability of package names and the high quality of the declaration files available. In summary I agree that working towards making typeshed more "DefinitelyTyped"-like is the better approach. |
One thing that can help with this is publishing mypy test runner separately as a pytest plugin, with this one write nice simple tests like in https://github.com/dropbox/sqlalchemy-stubs/blob/master/test/test-data/sqlalchemy-basics.test (it includes mypy as a submodule but we can't do this here, because typeshed is already a submodule in mypy). |
As I mentioned above, I also don't think that publishing all stubs in a single package is scalable.
This is reasonable at least for packages that are annotated, though currently we are missing tooling to generate stubs from annotated code. For packages without inline annotations, it may sometimes be better to have the stubs in typeshed (hopefully maintained by the package maintainer), at least if typeshed provides tooling that makes it easier to test and maintain the stubs.
Yes, the stubs can still be of low quality. However, we could have some infrastructure (such as ability to write tests) that would help maintain quality. We'd at least ensure that the stubs don't get completely broken and that they work with recent versions of tools. Being able to easily declare that everything in a stub should be annotated could also be helpful. My main argument is that if we have a central repository, any improvements to tooling around stubs immediately help all stubs in the repository (and new stubs), which makes things more scalable. Also, adding a new stub could be as simple as creating a PR with the stubs (+ tests). Alternatively, we could provide tools or even a project template to make it relatively easy to have similar things for decentralized stubs, but the barrier to entry would still be much higher. Somebody would have to create a GitHub repo, learn about available tooling, set things up correctly (including tests and Travis), keep track of issues, review PRs, etc. This works for big projects where there is a lot of developer interest, such as Django, but I fear that for less popular packages there is nobody willing to do this -- but somebody might be willing to make a one-time contribution with only the stubs (and a few tests). |
I'm trying to get a feel on how we should proceed. Personally, #2491 ("DefinitelyTypeshed") seems more promising than rejecting third-party stubs in the future. What does everyone else think? Reject 3rd party? DefiniteTypeshed? Keep the status quo for now? Another option? Whatever we decide, I will try to make some time to work on it. |
I'm in favor of moving forward with #2491. |
I have a contributor who is interested in adding .pyi type hints to ordered_set, and is trying to follow PEP 561 to make them get distributed and installed as part of the ordered_set distribution. He has not succeeded, and I don't know if this is a tooling problem or a documentation problem. The two of us can't even figure out what code in Python is supposed to make the I was going to suggest contributing the type hints to typeshed instead, but then I found this discussion. Am I right that PEP 561 is still very future-looking and doesn't work with most people's tooling? Here's a contributor who's very interested in adding type hints, and a maintainer who's interested in merging the PR when it works, and we're both unable to follow the PEP and get type hints installed. If this is the state of things and we're not missing something obvious, then typeshed should keep accepting new packages until its replacement works for more people. |
Oh. I figured out why PEP 561 isn't helping us: "This PEP does not support distributing typing information as part of module-only distributions." So PEP 561 doesn't cover everything. Is this also a case where typeshed wouldn't apply? |
@rspeer Sorry for the late answer. The best alternative I found is to convert ordered_set into a package, like I did with the asserts package. |
I am closing this in favor of #2491, since I feel the consensus is towards that solution. Please reopen if you think that there should be more discussion about this. |
Now that PEP 561 is supported by mypy I wonder whether we should accept new third party stubs into typeshed. Personally, I think we should steer those contributions to either be included into the parent package or to be distributed as a separate stubs package. This means that the people who actually care about those stubs (i.e. the submitters) can update the stubs more easily without having to go through the typeshed maintainers.
Maybe we could also offer a kind of "review service" (as time allows) for getting those packages off the ground?
The text was updated successfully, but these errors were encountered: