Skip to content

Commit

Permalink
Fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jhandley committed Oct 8, 2023
1 parent f7975b6 commit 661afb2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions tests/test_tree_sitter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from os import path
from typing import Dict, List, Optional, Tuple
from typing import Dict, List, Optional, Tuple, Union
from unittest import TestCase

from tree_sitter import (Language, LookaheadIterator, Node, Parser, Query,
Expand Down Expand Up @@ -1257,19 +1257,19 @@ def test_errors(self):

def collect_matches(
self,
matches: List[Tuple[int, Dict[str, Node|List[Node]]]],
matches: List[Tuple[int, Dict[str, Union[Node, List[Node]]]]],
) -> List[Tuple[int, List[Tuple[str, str]]]]:
return [(m[0], self.format_captures(m[1])) for m in matches]

def format_captures(
self,
captures: Dict[str, Node|List[Node]],
captures: Dict[str, Union[Node, List[Node]]],
) -> List[Tuple[str, str]]:
return [(name, self.format_capture(capture)) for name, capture in captures.items()]

def format_capture(
self,
capture: Node|List[Node]
capture: Union[Node, List[Node]]
) -> str:
return '[' + ", ".join(["'" + n.text.decode("utf-8") + "'" for n in capture]) + ']' if isinstance(capture, List) else capture.text.decode("utf-8")

Expand Down
4 changes: 2 additions & 2 deletions tree_sitter/binding.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Any, Callable, Iterable, List, Optional, Tuple
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union

import tree_sitter

Expand Down Expand Up @@ -355,7 +355,7 @@ class Query:
end_point: Optional[Tuple[int, int]] = None,
start_byte: Optional[int] = None,
end_byte: Optional[int] = None,
) -> List[Tuple[int, Dict[str, Node | List[Node]]]]:
) -> List[Tuple[int, Dict[str, Union[Node, List[Node]]]]]:
"""Get a list of all of the matches within the given node."""
...
def captures(
Expand Down

0 comments on commit 661afb2

Please sign in to comment.