typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Evaluate or document how to merge type stubs into existing codebase

Open kkirsche opened this issue 2 years ago • 4 comments

To simplify adoption of type hints in upstream repositories, this issue looks to better understand how maintainers upstream of typeshed can merge existing type stubs into their codebase.

In order to adopt inline type hints, upstream maintainers as I understand it currently need to manually merge existing stubs into their codebase.

To simplify the process, is there a tool to merge existing stubs into a project's codebase for faster adoption?

If so, is there documentation for it?

If not, is this something g that's worth evaluating and creating?

kkirsche avatar Aug 04 '22 11:08 kkirsche

To simplify the process, is there a tool to merge existing stubs into a project's codebase for faster adoption?

pytype's merge_pyi tool does this: https://github.com/google/pytype/tree/main/pytype/tools/merge_pyi

AlexWaygood avatar Aug 04 '22 11:08 AlexWaygood

There's an effort to improve documentation of Python-typing/typeshed etc. at https://typing.readthedocs.io/en/latest/index.html#. I don't know that pytype's merge_pyi tool is mentioned there, and it might be a useful thing to mention. If you'd like to improve that documentation, the source code is hosted at https://github.com/python/typing, and contributions are very welcome.

AlexWaygood avatar Aug 04 '22 11:08 AlexWaygood

You might also be interested in @JelleZijlstra's autotyping tool: https://github.com/JelleZijlstra/autotyping

AlexWaygood avatar Aug 04 '22 11:08 AlexWaygood

retype and libcst can also do this

hauntsaninja avatar Aug 04 '22 18:08 hauntsaninja

#8575 adds a more prominent link to https://typing.readthedocs.io/en/latest/index.html# to typeshed's README. I think any further documentation on this subject should go to that site rather than anywhere in the typeshed repo, so I propose closing this issue if that PR gets merged.

AlexWaygood avatar Aug 20 '22 16:08 AlexWaygood

I think that's reasonable.

In my opinion, it'd make sense to create an issue in the website's repository to add a section, similar to type checkers, for how this can be done. That's certainly not the only solution, but could be a starting point to get the ball rolling.

kkirsche avatar Aug 20 '22 18:08 kkirsche

In my opinion, it'd make sense to create an issue in the website's repository to add a section, similar to type checkers, for how this can be done. That's certainly not the only solution, but could be a starting point to get the ball rolling.

Sounds like a great idea! Feel free to make a PR over at https://github.com/python/typing, where that documentation is hosted :)

AlexWaygood avatar Aug 20 '22 18:08 AlexWaygood