py-tree-sitter icon indicating copy to clipboard operation
py-tree-sitter copied to clipboard

Add typing information

Open DorianCzichotzki opened this issue 4 years ago • 11 comments

Greate work on tree-sitter and the python binding. The only issue I found was, that there are no type hints. That makes it very hard to work with the package.

I created this PR to add a stub file containing the type definitions for the C extension. This should help tools like mypy and IDEs to show docstrings and provide better code completion support. I hope the definitions are complete.

DorianCzichotzki avatar Jul 26 '21 16:07 DorianCzichotzki

This is great. Is there a command we can run on CI that checks that the tests conform to the types declared in this file?

maxbrunsfeld avatar Jul 26 '21 16:07 maxbrunsfeld

Note there's another type stub I linked in this issue: https://github.com/tree-sitter/py-tree-sitter/issues/58

lunixbochs avatar Jul 26 '21 17:07 lunixbochs

@lunixbochs Sry did not see that.

@maxbrunsfeld I added mypy to check the test_tree_sitter.py module.

DorianCzichotzki avatar Jul 27 '21 09:07 DorianCzichotzki

I had to remove the mypy test for pypy. The typed-ast package is not able to build under pypy3.7 (see https://github.com/python/typed_ast/issues/111).

DorianCzichotzki avatar Jul 28 '21 21:07 DorianCzichotzki

Ok, I approved it so it's running and we can see if the CI passes.

@lunixbochs You're more familiar with Python tooling. Do you like this solution for adding types? I'm cool with it, since it seems to pass on CI.

maxbrunsfeld avatar Jul 28 '21 21:07 maxbrunsfeld

Is there something missing or anything I can do to get it merged?

DorianCzichotzki avatar Aug 10 '21 07:08 DorianCzichotzki

@DorianCzichotzki were these manually written? I believe you don't need the ... if you also have a docstring.

lunixbochs avatar Sep 22 '21 14:09 lunixbochs

what is needed for this to merge, it would be super helpful!

NorthIsUp avatar Mar 11 '22 23:03 NorthIsUp

I just need to find some time to merge the two approaches and update the stubs.

lunixbochs avatar Mar 12 '22 00:03 lunixbochs

Any update on this PR? I'd also like to use it :)

rorybyrne avatar Aug 05 '22 21:08 rorybyrne

I added tree-sitter stubs to typeshed. Run pip install types-tree-sitter to use them.

It would still be preferable to have them here, but it's a relatively small package, so typeshed maintainers will also do a good job of maintaining the stubs if the types never make it to py-tree-sitter.

Akuli avatar Aug 19 '22 22:08 Akuli

Superseded by #150

amaanq avatar Sep 05 '23 05:09 amaanq