From 863cd84304526d29135121cc38bec00c401567f6 Mon Sep 17 00:00:00 2001 From: Josh Handley Date: Sat, 7 Oct 2023 23:47:20 -0400 Subject: [PATCH] Fix type errors --- tests/test_tree_sitter.py | 8 ++++---- tree_sitter/_binding.pyi | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_tree_sitter.py b/tests/test_tree_sitter.py index ccbbbff..23482ec 100644 --- a/tests/test_tree_sitter.py +++ b/tests/test_tree_sitter.py @@ -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, Range, Tree @@ -1260,19 +1260,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") diff --git a/tree_sitter/_binding.pyi b/tree_sitter/_binding.pyi index 5e7e4a6..b53b824 100644 --- a/tree_sitter/_binding.pyi +++ b/tree_sitter/_binding.pyi @@ -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 @@ -349,7 +349,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(