-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add stubs for tree_sitter #8533
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
Changes from 12 commits
53eff01
f13b4f3
4e7162b
d774c41
5bc49ad
f1e1f56
bb9768a
cbe0622
129aaea
c7a0e95
fa3c7be
cec9ede
3dcf50f
cf2d227
2f6afc0
e424245
c76ed6f
989ffe7
8e982ee
6cfd208
44ab4a8
9ba7c0a
3f4498d
7112279
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# "self" argument is missing when stubtest inspects these methods | ||
tree_sitter.Node.child_by_field_id | ||
tree_sitter.Node.child_by_field_name | ||
tree_sitter.Node.sexp | ||
tree_sitter.Node.walk | ||
tree_sitter.Parser.parse | ||
tree_sitter.Parser.set_language | ||
tree_sitter.Tree.edit | ||
tree_sitter.Tree.walk | ||
tree_sitter.TreeCursor.current_field_name | ||
tree_sitter.TreeCursor.goto_first_child | ||
tree_sitter.TreeCursor.goto_next_sibling | ||
tree_sitter.TreeCursor.goto_parent | ||
tree_sitter.binding.Node.child_by_field_id | ||
tree_sitter.binding.Node.child_by_field_name | ||
tree_sitter.binding.Node.sexp | ||
tree_sitter.binding.Node.walk | ||
tree_sitter.binding.Parser.parse | ||
tree_sitter.binding.Parser.set_language | ||
tree_sitter.binding.Query.captures | ||
tree_sitter.binding.Query.matches | ||
tree_sitter.binding.Tree.edit | ||
tree_sitter.binding.Tree.walk | ||
tree_sitter.binding.TreeCursor.current_field_name | ||
tree_sitter.binding.TreeCursor.goto_first_child | ||
tree_sitter.binding.TreeCursor.goto_next_sibling | ||
tree_sitter.binding.TreeCursor.goto_parent | ||
|
||
# Runtime takes *args and **kwargs and ignores them. Passing arguments is most likely a mistake. | ||
tree_sitter.Parser.__init__ | ||
tree_sitter.binding.Parser.__init__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
version = "0.20.*" | ||
|
||
[tool.stubtest] | ||
ignore_missing_stub = false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from _typeshed import Incomplete, StrPath | ||
from collections.abc import Sequence | ||
|
||
# Query is missing at runtime for some reason | ||
from tree_sitter.binding import Node as Node, Parser as Parser, Tree as Tree, TreeCursor as TreeCursor | ||
|
||
class Language: | ||
@staticmethod | ||
def build_library(output_path: str, repo_paths: Sequence[StrPath]): ... | ||
name: str | ||
lib: Incomplete | ||
Akuli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
language_id: int | ||
# library_path is passed into ctypes LoadLibrary | ||
def __init__(self, library_path: str, name: str) -> None: ... | ||
def field_id_for_name(self, name): ... | ||
def query(self, source): ... |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,95 @@ | ||||||||
from _typeshed import Incomplete | ||||||||
from typing import ClassVar | ||||||||
from typing_extensions import final | ||||||||
|
||||||||
from tree_sitter import Language | ||||||||
|
||||||||
@final | ||||||||
class Node: | ||||||||
@property | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a bunch of other properties: https://github.com/tree-sitter/py-tree-sitter/blob/7dc704fa37057c685fe2d86611f318146c95c34d/tree_sitter/binding.c#L501. I didn't check them all but you're missing at least There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These don't exist in the latest released version of py-tree-sitter (0.20.0). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That'll teach me to look at the master branch :) |
||||||||
def start_byte(self) -> int: ... | ||||||||
@property | ||||||||
def start_point(self) -> tuple[int, int]: ... | ||||||||
@property | ||||||||
def end_byte(self) -> int: ... | ||||||||
@property | ||||||||
def end_point(self) -> tuple[int, int]: ... | ||||||||
@property | ||||||||
def has_changes(self) -> bool: ... | ||||||||
@property | ||||||||
def has_error(self) -> bool: ... | ||||||||
@property | ||||||||
def is_missing(self) -> bool: ... | ||||||||
@property | ||||||||
def is_named(self) -> bool: ... | ||||||||
@property | ||||||||
def child_count(self) -> int: ... | ||||||||
@property | ||||||||
def named_child_count(self) -> bool: ... | ||||||||
@property | ||||||||
def children(self) -> list[Node]: ... | ||||||||
@property | ||||||||
def next_named_sibling(self) -> Node | None: ... | ||||||||
@property | ||||||||
def next_sibling(self) -> Node | None: ... | ||||||||
@property | ||||||||
def parent(self) -> Node | None: ... | ||||||||
@property | ||||||||
def prev_named_sibling(self) -> Node | None: ... | ||||||||
@property | ||||||||
def prev_sibling(self) -> Node | None: ... | ||||||||
@property | ||||||||
def text(self) -> bytes: ... | ||||||||
Akuli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
@property | ||||||||
def type(self) -> str: ... | ||||||||
__hash__: ClassVar[None] # type: ignore[assignment] | ||||||||
def child_by_field_id(self, __id: int) -> Node | None: ... | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are more methods: children_by_field_id, children_by_field_name, field_name_for_child There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are not in the latest released version. |
||||||||
def child_by_field_name(self, __name: str) -> Node | None: ... | ||||||||
def sexp(self) -> str: ... | ||||||||
def walk(self) -> TreeCursor: ... | ||||||||
def __eq__(self, other: object) -> bool: ... | ||||||||
def __ne__(self, other: object) -> bool: ... | ||||||||
# There are __ge__, __gt__, __le__, __lt__ methods but they seem to always return False | ||||||||
Akuli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
# | ||||||||
# >>> n | ||||||||
# <Node kind=call, start_point=(0, 0), end_point=(0, 14)> | ||||||||
# >>> n >= "", n <= "", n >= 0, n <= 0, n >= (0,0), n <= (0,0) | ||||||||
# (False, False, False, False, False, False) | ||||||||
|
||||||||
@final | ||||||||
class Parser: | ||||||||
# At runtime, Parser(1, 2, 3) ignores the arguments, but that's most likely buggy code | ||||||||
def __init__(self) -> None: ... | ||||||||
def parse(self, source: bytes, old_tree: Tree | None = ..., keep_text: bool = ...) -> Tree: ... | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Source can be any ReadableBuffer, or a Callable: https://github.com/tree-sitter/py-tree-sitter/blob/7dc704fa37057c685fe2d86611f318146c95c34d/tree_sitter/binding.c#L960 Looking at https://github.com/tree-sitter/py-tree-sitter/blob/7dc704fa37057c685fe2d86611f318146c95c34d/tree_sitter/binding.c#L895 it seems to be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Version in pypi is more strict:
|
||||||||
def set_language(self, __language: Language) -> None: ... | ||||||||
|
||||||||
@final | ||||||||
class Query: | ||||||||
def captures(self, *args, **kwargs): ... | ||||||||
Akuli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
def matches(self, *args, **kwargs): ... | ||||||||
Akuli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
@final | ||||||||
class Tree: | ||||||||
@property | ||||||||
def root_node(self) -> Node: ... | ||||||||
@property | ||||||||
def text(self) -> bytes: ... | ||||||||
Akuli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
def edit( | ||||||||
self, | ||||||||
start_byte: int, | ||||||||
old_end_byte: int, | ||||||||
new_end_byte: int, | ||||||||
start_point: tuple[int, int], | ||||||||
old_end_point: tuple[int, int], | ||||||||
new_end_point: tuple[int, int], | ||||||||
) -> None: ... | ||||||||
def walk(self) -> TreeCursor: ... | ||||||||
|
||||||||
@final | ||||||||
class TreeCursor: | ||||||||
@property | ||||||||
def node(self) -> Node: ... | ||||||||
def current_field_name(self) -> None | Incomplete: ... | ||||||||
Akuli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
def goto_first_child(self) -> bool: ... | ||||||||
def goto_next_sibling(self) -> bool: ... | ||||||||
def goto_parent(self) -> bool: ... | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
One more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't exist in the released version. |
Uh oh!
There was an error while loading. Please reload this page.