Skip to content

Commit

Permalink
Use isinstance(v, Token)
Browse files Browse the repository at this point in the history
  • Loading branch information
makukha committed Jan 3, 2025
1 parent 01c4f42 commit c48b7d3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lark/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from typing import List, Callable, Iterator, Union, Optional, Generic, TypeVar, TYPE_CHECKING

from .lexer import Token

if TYPE_CHECKING:
from .lexer import TerminalDef, Token
from .lexer import TerminalDef
try:
import rich
except ImportError:
Expand Down Expand Up @@ -179,7 +181,7 @@ def find_token(self, token_type: str) -> Iterator[_Leaf_T]:
Example:
>>> term_tokens = tree.find_token('TERM')
"""
return self.scan_values(lambda v: not isinstance(v, Tree) and v.type == token_type)
return self.scan_values(lambda v: isinstance(v, Token) and v.type == token_type)

def expand_kids_by_data(self, *data_values):
"""Expand (inline) children with any of the given data values. Returns True if anything changed"""
Expand Down

0 comments on commit c48b7d3

Please sign in to comment.