From 53eff01dc2e222e240fd3eb420406c871b4daf39 Mon Sep 17 00:00:00 2001 From: Akuli Date: Mon, 8 Aug 2022 19:54:08 +0300 Subject: [PATCH 01/24] python3 scripts/create_baseline_stubs.py tree-sitter --- pyrightconfig.stricter.json | 1 + stubs/tree-sitter/METADATA.toml | 4 ++ stubs/tree-sitter/tree_sitter/__init__.pyi | 13 +++++ stubs/tree-sitter/tree_sitter/binding.pyi | 58 ++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 stubs/tree-sitter/METADATA.toml create mode 100644 stubs/tree-sitter/tree_sitter/__init__.pyi create mode 100644 stubs/tree-sitter/tree_sitter/binding.pyi diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 798b9e9c9de4..4ec042db84e6 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -87,6 +87,7 @@ "stubs/SQLAlchemy", "stubs/stripe", "stubs/tqdm", + "stubs/tree-sitter", "stubs/tzlocal/tzlocal/utils.pyi", "stubs/ttkthemes", "stubs/urllib3", diff --git a/stubs/tree-sitter/METADATA.toml b/stubs/tree-sitter/METADATA.toml new file mode 100644 index 000000000000..997ea098d4ca --- /dev/null +++ b/stubs/tree-sitter/METADATA.toml @@ -0,0 +1,4 @@ +version = "0.20.*" + +[tool.stubtest] +ignore_missing_stub = false diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi new file mode 100644 index 000000000000..113393fa7955 --- /dev/null +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -0,0 +1,13 @@ +from typing import Any + +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, repo_paths): ... + name: Any + lib: Any + language_id: Any + def __init__(self, library_path, name) -> None: ... + def field_id_for_name(self, name): ... + def query(self, source): ... diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi new file mode 100644 index 000000000000..db396fed6b01 --- /dev/null +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -0,0 +1,58 @@ +from typing import Any, ClassVar + +class Node: + child_count: ClassVar[getset_descriptor] = ... + children: ClassVar[getset_descriptor] = ... + end_byte: ClassVar[getset_descriptor] = ... + end_point: ClassVar[getset_descriptor] = ... + has_changes: ClassVar[getset_descriptor] = ... + has_error: ClassVar[getset_descriptor] = ... + is_missing: ClassVar[getset_descriptor] = ... + is_named: ClassVar[getset_descriptor] = ... + named_child_count: ClassVar[getset_descriptor] = ... + next_named_sibling: ClassVar[getset_descriptor] = ... + next_sibling: ClassVar[getset_descriptor] = ... + parent: ClassVar[getset_descriptor] = ... + prev_named_sibling: ClassVar[getset_descriptor] = ... + prev_sibling: ClassVar[getset_descriptor] = ... + start_byte: ClassVar[getset_descriptor] = ... + start_point: ClassVar[getset_descriptor] = ... + text: ClassVar[getset_descriptor] = ... + type: ClassVar[getset_descriptor] = ... + __hash__: ClassVar[None] = ... + def child_by_field_id(self, *args, **kwargs) -> Any: ... + def child_by_field_name(self, *args, **kwargs) -> Any: ... + def sexp(self, *args, **kwargs) -> Any: ... + def walk(self, *args, **kwargs) -> Any: ... + def __eq__(self, other) -> Any: ... + def __ge__(self, other) -> Any: ... + def __gt__(self, other) -> Any: ... + def __le__(self, other) -> Any: ... + def __lt__(self, other) -> Any: ... + def __ne__(self, other) -> Any: ... + +class Parser: + @classmethod + def __init__(cls, *args, **kwargs) -> None: ... + def parse(self, *args, **kwargs) -> Any: ... + def set_language(self, *args, **kwargs) -> Any: ... + +class Query: + def captures(self, *args, **kwargs) -> Any: ... + def matches(self, *args, **kwargs) -> Any: ... + +class Tree: + root_node: ClassVar[getset_descriptor] = ... + text: ClassVar[getset_descriptor] = ... + def edit(self, *args, **kwargs) -> Any: ... + def walk(self, *args, **kwargs) -> Any: ... + +class TreeCursor: + node: ClassVar[getset_descriptor] = ... + def current_field_name(self, *args, **kwargs) -> Any: ... + def goto_first_child(self, *args, **kwargs) -> Any: ... + def goto_next_sibling(self, *args, **kwargs) -> Any: ... + def goto_parent(self, *args, **kwargs) -> Any: ... + +def _language_field_id_for_name(*args, **kwargs) -> Any: ... +def _language_query(*args, **kwargs) -> Any: ... From f13b4f3a3c3e61d73a589d763088e58abd7d6f9b Mon Sep 17 00:00:00 2001 From: Akuli Date: Mon, 8 Aug 2022 20:22:05 +0300 Subject: [PATCH 02/24] manual stubbing --- stubs/tree-sitter/tree_sitter/__init__.pyi | 12 +-- stubs/tree-sitter/tree_sitter/binding.pyi | 99 ++++++++++++---------- 2 files changed, 59 insertions(+), 52 deletions(-) diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index 113393fa7955..0e079fdd870d 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -1,13 +1,15 @@ +from _typeshed import StrPath, Incomplete from typing import Any 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, repo_paths): ... - name: Any - lib: Any - language_id: Any - def __init__(self, library_path, name) -> None: ... + def build_library(output_path: str, repo_paths: Sequence[StrPath]): ... + name: str + lib: Incomplete + language_id: int + # 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): ... diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index db396fed6b01..d290f700d473 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -1,58 +1,63 @@ from typing import Any, ClassVar +from _typeshed import Incomplete +from tree_sitter import Language class Node: - child_count: ClassVar[getset_descriptor] = ... - children: ClassVar[getset_descriptor] = ... - end_byte: ClassVar[getset_descriptor] = ... - end_point: ClassVar[getset_descriptor] = ... - has_changes: ClassVar[getset_descriptor] = ... - has_error: ClassVar[getset_descriptor] = ... - is_missing: ClassVar[getset_descriptor] = ... - is_named: ClassVar[getset_descriptor] = ... - named_child_count: ClassVar[getset_descriptor] = ... - next_named_sibling: ClassVar[getset_descriptor] = ... - next_sibling: ClassVar[getset_descriptor] = ... - parent: ClassVar[getset_descriptor] = ... - prev_named_sibling: ClassVar[getset_descriptor] = ... - prev_sibling: ClassVar[getset_descriptor] = ... - start_byte: ClassVar[getset_descriptor] = ... - start_point: ClassVar[getset_descriptor] = ... - text: ClassVar[getset_descriptor] = ... - type: ClassVar[getset_descriptor] = ... - __hash__: ClassVar[None] = ... - def child_by_field_id(self, *args, **kwargs) -> Any: ... - def child_by_field_name(self, *args, **kwargs) -> Any: ... - def sexp(self, *args, **kwargs) -> Any: ... - def walk(self, *args, **kwargs) -> Any: ... - def __eq__(self, other) -> Any: ... - def __ge__(self, other) -> Any: ... - def __gt__(self, other) -> Any: ... - def __le__(self, other) -> Any: ... - def __lt__(self, other) -> Any: ... - def __ne__(self, other) -> Any: ... + start_byte: int + start_point: tuple[int,int] + end_byte:int + end_point:tuple[int,int] + has_changes:bool + has_error:bool + is_missing:bool + is_named:bool + child_count:int + named_child_count:bool + children:list[Node] + next_named_sibling: Node|None + next_sibling: Node|None + parent: Node|None + prev_named_sibling: Node|None + prev_sibling: Node|None + text: bytes + type: str + __hash__: ClassVar[None] # type: ignore[assignment] + def child_by_field_id(self, __id: int) -> Node|None: ... + 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 + # + # >>> n + # + # >>> n >= "", n <= "", n >= 0, n <= 0, n >= (0,0), n <= (0,0) + # (False, False, False, False, False, False) + def __ge__(self, other:object)->bool: ... + def __gt__(self, other:object)->bool: ... + def __le__(self, other:object)->bool: ... + def __lt__(self, other:object)->bool: ... class Parser: - @classmethod - def __init__(cls, *args, **kwargs) -> None: ... - def parse(self, *args, **kwargs) -> Any: ... - def set_language(self, *args, **kwargs) -> Any: ... + # 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: ... + def set_language(self, __language: Language) -> None: ... class Query: - def captures(self, *args, **kwargs) -> Any: ... - def matches(self, *args, **kwargs) -> Any: ... + def captures(self, *args, **kwargs): ... + def matches(self, *args, **kwargs): ... class Tree: - root_node: ClassVar[getset_descriptor] = ... - text: ClassVar[getset_descriptor] = ... - def edit(self, *args, **kwargs) -> Any: ... - def walk(self, *args, **kwargs) -> Any: ... + root_node: Node + text: bytes + 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: ... class TreeCursor: - node: ClassVar[getset_descriptor] = ... - def current_field_name(self, *args, **kwargs) -> Any: ... - def goto_first_child(self, *args, **kwargs) -> Any: ... - def goto_next_sibling(self, *args, **kwargs) -> Any: ... - def goto_parent(self, *args, **kwargs) -> Any: ... - -def _language_field_id_for_name(*args, **kwargs) -> Any: ... -def _language_query(*args, **kwargs) -> Any: ... + node: Node + def current_field_name(self) -> None | Incomplete: ... + def goto_first_child(self) -> bool: ... + def goto_next_sibling(self) -> bool: ... + def goto_parent(self) -> bool: ... From 4e7162b9a7ca2f1ff9492c22a639b566f30f19d6 Mon Sep 17 00:00:00 2001 From: Akuli Date: Mon, 8 Aug 2022 20:25:12 +0300 Subject: [PATCH 03/24] make all the things read-only --- stubs/tree-sitter/tree_sitter/binding.pyi | 63 +++++++++++++++-------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index d290f700d473..2dda3d9b5649 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -3,24 +3,42 @@ from _typeshed import Incomplete from tree_sitter import Language class Node: - start_byte: int - start_point: tuple[int,int] - end_byte:int - end_point:tuple[int,int] - has_changes:bool - has_error:bool - is_missing:bool - is_named:bool - child_count:int - named_child_count:bool - children:list[Node] - next_named_sibling: Node|None - next_sibling: Node|None - parent: Node|None - prev_named_sibling: Node|None - prev_sibling: Node|None - text: bytes - type: str + @property + 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: ... + @property + def type(self) -> str: ... __hash__: ClassVar[None] # type: ignore[assignment] def child_by_field_id(self, __id: int) -> Node|None: ... def child_by_field_name(self,__name:str)->Node|None: ... @@ -50,13 +68,16 @@ class Query: def matches(self, *args, **kwargs): ... class Tree: - root_node: Node - text: bytes + @property + def root_node(self)-> Node:... + @property + def text(self)->bytes:... 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: ... class TreeCursor: - node: Node + @property + def node(self)->Node:... def current_field_name(self) -> None | Incomplete: ... def goto_first_child(self) -> bool: ... def goto_next_sibling(self) -> bool: ... From d774c41fc1ab61f7bb669a1077e0791117214aeb Mon Sep 17 00:00:00 2001 From: Akuli Date: Mon, 8 Aug 2022 20:55:48 +0300 Subject: [PATCH 04/24] clarification --- stubs/tree-sitter/tree_sitter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index 0e079fdd870d..0697744357ce 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -9,7 +9,7 @@ class Language: name: str lib: Incomplete language_id: int - # path is passed into ctypes LoadLibrary + # 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): ... From 5bc49ade3e5282745cfd945309fc9f2eaca01e20 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 11 Aug 2022 19:11:35 +0000 Subject: [PATCH 05/24] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/tree-sitter/tree_sitter/__init__.pyi | 2 +- stubs/tree-sitter/tree_sitter/binding.pyi | 61 +++++++++++++--------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index 0697744357ce..d94d6efcd295 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -1,4 +1,4 @@ -from _typeshed import StrPath, Incomplete +from _typeshed import Incomplete, StrPath from typing import Any from tree_sitter.binding import Node as Node, Parser as Parser, Tree as Tree, TreeCursor as TreeCursor diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index 2dda3d9b5649..7645a0c953a2 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -1,16 +1,17 @@ -from typing import Any, ClassVar from _typeshed import Incomplete +from typing import ClassVar + from tree_sitter import Language class Node: @property - def start_byte(self) -> int: ... + def start_byte(self) -> int: ... @property - def start_point(self) -> tuple[int,int]: ... + def start_point(self) -> tuple[int, int]: ... @property def end_byte(self) -> int: ... @property - def end_point(self) -> tuple[int,int]: ... + def end_point(self) -> tuple[int, int]: ... @property def has_changes(self) -> bool: ... @property @@ -26,36 +27,36 @@ class Node: @property def children(self) -> list[Node]: ... @property - def next_named_sibling(self) -> Node|None: ... + def next_named_sibling(self) -> Node | None: ... @property - def next_sibling(self) -> Node|None: ... + def next_sibling(self) -> Node | None: ... @property - def parent(self) -> Node|None: ... + def parent(self) -> Node | None: ... @property - def prev_named_sibling(self) -> Node|None: ... + def prev_named_sibling(self) -> Node | None: ... @property - def prev_sibling(self) -> Node|None: ... + def prev_sibling(self) -> Node | None: ... @property - def text(self) -> bytes: ... + def text(self) -> bytes: ... @property - def type(self) -> str: ... + def type(self) -> str: ... __hash__: ClassVar[None] # type: ignore[assignment] - def child_by_field_id(self, __id: int) -> Node|None: ... - 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: ... + def child_by_field_id(self, __id: int) -> Node | None: ... + 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 # # >>> n # # >>> n >= "", n <= "", n >= 0, n <= 0, n >= (0,0), n <= (0,0) # (False, False, False, False, False, False) - def __ge__(self, other:object)->bool: ... - def __gt__(self, other:object)->bool: ... - def __le__(self, other:object)->bool: ... - def __lt__(self, other:object)->bool: ... + def __ge__(self, other: object) -> bool: ... + def __gt__(self, other: object) -> bool: ... + def __le__(self, other: object) -> bool: ... + def __lt__(self, other: object) -> bool: ... class Parser: # At runtime, Parser(1, 2, 3) ignores the arguments, but that's most likely buggy code @@ -69,15 +70,23 @@ class Query: class Tree: @property - def root_node(self)-> Node:... - @property - def text(self)->bytes:... - 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 root_node(self) -> Node: ... + @property + def text(self) -> bytes: ... + 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: ... class TreeCursor: @property - def node(self)->Node:... + def node(self) -> Node: ... def current_field_name(self) -> None | Incomplete: ... def goto_first_child(self) -> bool: ... def goto_next_sibling(self) -> bool: ... From f1e1f5663c4709f2d167ed8926778f8f04871439 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 11 Aug 2022 22:15:24 +0300 Subject: [PATCH 06/24] fix --- stubs/tree-sitter/tree_sitter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index d94d6efcd295..060ee9652a4b 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete, StrPath -from typing import Any +from typing import Sequence from tree_sitter.binding import Node as Node, Parser as Parser, Tree as Tree, TreeCursor as TreeCursor From bb9768a35676aeb835b6f03be63ed04ff2560cf9 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 11 Aug 2022 22:25:10 +0300 Subject: [PATCH 07/24] import the correct Sequence --- stubs/tree-sitter/tree_sitter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index 060ee9652a4b..cc8c9fcaf201 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -1,5 +1,5 @@ from _typeshed import Incomplete, StrPath -from typing import Sequence +from collections.abc import Sequence from tree_sitter.binding import Node as Node, Parser as Parser, Tree as Tree, TreeCursor as TreeCursor From cbe0622465323ccb0a979afa983b5b94f7266172 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 11 Aug 2022 22:28:41 +0300 Subject: [PATCH 08/24] allowlist --- .../tree-sitter/@tests/stubtest_allowlist.txt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 stubs/tree-sitter/@tests/stubtest_allowlist.txt diff --git a/stubs/tree-sitter/@tests/stubtest_allowlist.txt b/stubs/tree-sitter/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..d1584ff2f9ee --- /dev/null +++ b/stubs/tree-sitter/@tests/stubtest_allowlist.txt @@ -0,0 +1,39 @@ +# For whatever reasons, many methods (implemented in C) appear to have +# "*args, **kwargs" even though they don't actually accept anything. +tree_sitter.Node +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 +tree_sitter.Parser.__init__ +tree_sitter.Parser.parse +tree_sitter.Parser.set_language +tree_sitter.Tree +tree_sitter.Tree.edit +tree_sitter.Tree.walk +tree_sitter.TreeCursor +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 +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 +tree_sitter.binding.Parser.__init__ +tree_sitter.binding.Parser.parse +tree_sitter.binding.Parser.set_language +tree_sitter.binding.Query +tree_sitter.binding.Query.captures +tree_sitter.binding.Query.matches +tree_sitter.binding.Tree +tree_sitter.binding.Tree.edit +tree_sitter.binding.Tree.walk +tree_sitter.binding.TreeCursor +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 From 129aaeaabd6ff3a789c719f0bcfe92dab7b2553a Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 11 Aug 2022 22:51:18 +0300 Subject: [PATCH 09/24] review allowlist manually --- .../tree-sitter/@tests/stubtest_allowlist.txt | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/stubs/tree-sitter/@tests/stubtest_allowlist.txt b/stubs/tree-sitter/@tests/stubtest_allowlist.txt index d1584ff2f9ee..3635f5014de3 100644 --- a/stubs/tree-sitter/@tests/stubtest_allowlist.txt +++ b/stubs/tree-sitter/@tests/stubtest_allowlist.txt @@ -1,39 +1,42 @@ -# For whatever reasons, many methods (implemented in C) appear to have -# "*args, **kwargs" even though they don't actually accept anything. -tree_sitter.Node +# "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 -tree_sitter.Parser.__init__ tree_sitter.Parser.parse tree_sitter.Parser.set_language -tree_sitter.Tree tree_sitter.Tree.edit tree_sitter.Tree.walk -tree_sitter.TreeCursor 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 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 -tree_sitter.binding.Parser.__init__ tree_sitter.binding.Parser.parse tree_sitter.binding.Parser.set_language tree_sitter.binding.Query tree_sitter.binding.Query.captures tree_sitter.binding.Query.matches -tree_sitter.binding.Tree tree_sitter.binding.Tree.edit tree_sitter.binding.Tree.walk -tree_sitter.binding.TreeCursor 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__ + +# TODO +tree_sitter.Node +tree_sitter.Parser +tree_sitter.Tree +tree_sitter.TreeCursor +tree_sitter.binding.Node +tree_sitter.binding.Parser +tree_sitter.binding.Tree +tree_sitter.binding.TreeCursor From c7a0e95389b0382792e87ab088fbb9b46590f6ee Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 11 Aug 2022 22:55:41 +0300 Subject: [PATCH 10/24] fixenings --- stubs/tree-sitter/@tests/stubtest_allowlist.txt | 11 ----------- stubs/tree-sitter/tree_sitter/__init__.pyi | 1 + stubs/tree-sitter/tree_sitter/binding.pyi | 7 ++++++- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/stubs/tree-sitter/@tests/stubtest_allowlist.txt b/stubs/tree-sitter/@tests/stubtest_allowlist.txt index 3635f5014de3..0b012eb99055 100644 --- a/stubs/tree-sitter/@tests/stubtest_allowlist.txt +++ b/stubs/tree-sitter/@tests/stubtest_allowlist.txt @@ -17,7 +17,6 @@ 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 tree_sitter.binding.Query.captures tree_sitter.binding.Query.matches tree_sitter.binding.Tree.edit @@ -30,13 +29,3 @@ 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__ - -# TODO -tree_sitter.Node -tree_sitter.Parser -tree_sitter.Tree -tree_sitter.TreeCursor -tree_sitter.binding.Node -tree_sitter.binding.Parser -tree_sitter.binding.Tree -tree_sitter.binding.TreeCursor diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index cc8c9fcaf201..02006b7eddba 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -1,6 +1,7 @@ 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: diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index 7645a0c953a2..d29f9adf474d 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -1,8 +1,9 @@ from _typeshed import Incomplete -from typing import ClassVar +from typing import ClassVar, final from tree_sitter import Language +@final class Node: @property def start_byte(self) -> int: ... @@ -58,16 +59,19 @@ class Node: def __le__(self, other: object) -> bool: ... def __lt__(self, other: object) -> bool: ... +@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: ... def set_language(self, __language: Language) -> None: ... +@final class Query: def captures(self, *args, **kwargs): ... def matches(self, *args, **kwargs): ... +@final class Tree: @property def root_node(self) -> Node: ... @@ -84,6 +88,7 @@ class Tree: ) -> None: ... def walk(self) -> TreeCursor: ... +@final class TreeCursor: @property def node(self) -> Node: ... From fa3c7bed044bb504f6efd7ea110260fa9ebf5dbf Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 11 Aug 2022 23:00:16 +0300 Subject: [PATCH 11/24] fix final import --- stubs/tree-sitter/tree_sitter/binding.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index d29f9adf474d..3932792fd19e 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -1,5 +1,6 @@ from _typeshed import Incomplete -from typing import ClassVar, final +from typing import ClassVar +from typing_extensions import final from tree_sitter import Language From cec9ede84bfd59e8bb5587debad09d0fec8913fb Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 11 Aug 2022 23:09:34 +0300 Subject: [PATCH 12/24] Delete comparing methods, unlikely to be useful --- stubs/tree-sitter/tree_sitter/binding.pyi | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index 3932792fd19e..177d8047f734 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -55,10 +55,6 @@ class Node: # # >>> n >= "", n <= "", n >= 0, n <= 0, n >= (0,0), n <= (0,0) # (False, False, False, False, False, False) - def __ge__(self, other: object) -> bool: ... - def __gt__(self, other: object) -> bool: ... - def __le__(self, other: object) -> bool: ... - def __lt__(self, other: object) -> bool: ... @final class Parser: From 3dcf50ffe76b0afceb8941c864fde13bd349b288 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 12 Aug 2022 21:04:23 +0300 Subject: [PATCH 13/24] Update stubs/tree-sitter/tree_sitter/__init__.pyi Co-authored-by: Alex Waygood --- stubs/tree-sitter/tree_sitter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index 02006b7eddba..fa35ed5b8eb9 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -8,7 +8,7 @@ class Language: @staticmethod def build_library(output_path: str, repo_paths: Sequence[StrPath]): ... name: str - lib: Incomplete + lib: ctypes.CDLL language_id: int # library_path is passed into ctypes LoadLibrary def __init__(self, library_path: str, name: str) -> None: ... From cf2d227b1e4b8bee7515f427b86d22b98ae4e3c8 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 12 Aug 2022 21:04:29 +0300 Subject: [PATCH 14/24] Update stubs/tree-sitter/tree_sitter/__init__.pyi Co-authored-by: Alex Waygood --- stubs/tree-sitter/tree_sitter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index fa35ed5b8eb9..905a4e004959 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -6,7 +6,7 @@ from tree_sitter.binding import Node as Node, Parser as Parser, Tree as Tree, Tr class Language: @staticmethod - def build_library(output_path: str, repo_paths: Sequence[StrPath]): ... + def build_library(output_path: str, repo_paths: Sequence[StrPath]) -> bool: ... name: str lib: ctypes.CDLL language_id: int From 2f6afc0647da0ef046945239bcd2915d2c14ab17 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 12 Aug 2022 21:08:13 +0300 Subject: [PATCH 15/24] fix import --- stubs/tree-sitter/tree_sitter/__init__.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index 905a4e004959..9fe58ab68ef4 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -1,3 +1,4 @@ +import ctypes from _typeshed import Incomplete, StrPath from collections.abc import Sequence From e42424584e643a34048f3aa902b29de210a0ff2d Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 12 Aug 2022 21:23:48 +0300 Subject: [PATCH 16/24] asd asd --- stubs/tree-sitter/tree_sitter/__init__.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/__init__.pyi b/stubs/tree-sitter/tree_sitter/__init__.pyi index 9fe58ab68ef4..2450e0a9540f 100644 --- a/stubs/tree-sitter/tree_sitter/__init__.pyi +++ b/stubs/tree-sitter/tree_sitter/__init__.pyi @@ -1,5 +1,5 @@ import ctypes -from _typeshed import Incomplete, StrPath +from _typeshed import StrPath from collections.abc import Sequence # Query is missing at runtime for some reason From c76ed6fa89e9b8239469fab5abd1b25f2143cd24 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 13 Aug 2022 17:40:39 +0300 Subject: [PATCH 17/24] Update stubs/tree-sitter/tree_sitter/binding.pyi Co-authored-by: Jelle Zijlstra --- stubs/tree-sitter/tree_sitter/binding.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index 177d8047f734..d0969e8d9758 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -89,7 +89,7 @@ class Tree: class TreeCursor: @property def node(self) -> Node: ... - def current_field_name(self) -> None | Incomplete: ... + def current_field_name(self) -> str | None: ... def goto_first_child(self) -> bool: ... def goto_next_sibling(self) -> bool: ... def goto_parent(self) -> bool: ... From 989ffe73ca0163fa3a843045a7316c9a0c9aabd1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 13 Aug 2022 14:41:46 +0000 Subject: [PATCH 18/24] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/tree-sitter/tree_sitter/binding.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index d0969e8d9758..73c2cad7a462 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -1,4 +1,3 @@ -from _typeshed import Incomplete from typing import ClassVar from typing_extensions import final From 8e982ee4b39e7c38dac1e751a5945e9a652770a7 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 13 Aug 2022 17:42:09 +0300 Subject: [PATCH 19/24] Update stubs/tree-sitter/tree_sitter/binding.pyi --- stubs/tree-sitter/tree_sitter/binding.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index 73c2cad7a462..ac8775983807 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -65,7 +65,6 @@ class Parser: @final class Query: def captures(self, *args, **kwargs): ... - def matches(self, *args, **kwargs): ... @final class Tree: From 6cfd208ac845bb430e25222972b22541afb0d590 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 13 Aug 2022 17:42:17 +0300 Subject: [PATCH 20/24] Update stubs/tree-sitter/tree_sitter/binding.pyi --- stubs/tree-sitter/tree_sitter/binding.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index ac8775983807..a5a2a1e154a3 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -64,7 +64,8 @@ class Parser: @final class Query: - def captures(self, *args, **kwargs): ... + # start_point and end_point arguments don't seem to do anything + def captures(self) -> list[tuple[Node, str]]: ... @final class Tree: From 44ab4a8f4b13472989d3790fc61536223ea3dd70 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 13 Aug 2022 17:42:26 +0300 Subject: [PATCH 21/24] Update stubs/tree-sitter/tree_sitter/binding.pyi --- stubs/tree-sitter/tree_sitter/binding.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index a5a2a1e154a3..e2c5c75b240b 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -72,7 +72,7 @@ class Tree: @property def root_node(self) -> Node: ... @property - def text(self) -> bytes: ... + def text(self) -> bytes | Any: ... # technically ReadableBuffer | Any def edit( self, start_byte: int, From 9ba7c0ae9bb0c8bdd77a26f9af6f26527346049c Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 13 Aug 2022 17:43:11 +0300 Subject: [PATCH 22/24] Update stubs/tree-sitter/tree_sitter/binding.pyi --- stubs/tree-sitter/tree_sitter/binding.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index e2c5c75b240b..138768cd8354 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -38,7 +38,7 @@ class Node: @property def prev_sibling(self) -> Node | None: ... @property - def text(self) -> bytes: ... + def text(self) -> bytes | Any: ... # can be None, but annoying to check @property def type(self) -> str: ... __hash__: ClassVar[None] # type: ignore[assignment] From 3f4498d7d9f729efba5a181ace4f59a4ac8fbc9c Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 13 Aug 2022 17:45:59 +0300 Subject: [PATCH 23/24] import --- stubs/tree-sitter/tree_sitter/binding.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index 138768cd8354..50291ec0c87b 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -1,4 +1,4 @@ -from typing import ClassVar +from typing import Any, ClassVar from typing_extensions import final from tree_sitter import Language From 7112279db0307bec10d94e19130d3988766db59f Mon Sep 17 00:00:00 2001 From: Akuli Date: Sat, 13 Aug 2022 17:47:41 +0300 Subject: [PATCH 24/24] Update stubs/tree-sitter/tree_sitter/binding.pyi --- stubs/tree-sitter/tree_sitter/binding.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/tree-sitter/tree_sitter/binding.pyi b/stubs/tree-sitter/tree_sitter/binding.pyi index 50291ec0c87b..8e175394426a 100644 --- a/stubs/tree-sitter/tree_sitter/binding.pyi +++ b/stubs/tree-sitter/tree_sitter/binding.pyi @@ -48,7 +48,7 @@ class Node: 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 + # There are __ge__, __gt__, __le__, __lt__ methods but they always return False # # >>> n #