Improvements to type checking

- Improved/fixed the type of the examples parameter of the match_examples method of UnexpectedInput (Mapping vs. Dict)

- Added a py.typed marker file
This commit is contained in:
ornariece 2021-09-13 16:27:28 +02:00
parent 2335aa63e1
commit 349e1432d3
3 changed files with 5 additions and 4 deletions

View File

@ -1,5 +1,6 @@
from .utils import logger, NO_VALUE
from typing import Dict, Iterable, Callable, Union, TypeVar, Tuple, Any, List, Set, Optional, Collection, TYPE_CHECKING
from typing import Mapping, Iterable, Callable, Union, TypeVar, Tuple, Any, List, Set, Optional, Collection, \
TYPE_CHECKING
if TYPE_CHECKING:
from .lexer import Token
@ -73,7 +74,7 @@ class UnexpectedInput(LarkError):
return (before + after + b'\n' + b' ' * len(before.expandtabs()) + b'^\n').decode("ascii", "backslashreplace")
def match_examples(self, parse_fn: 'Callable[[str], Tree]',
examples: Union[Dict[T, Iterable[str]], Iterable[Tuple[T, Iterable[str]]]],
examples: Union[Mapping[T, Iterable[str]], Iterable[Tuple[T, Iterable[str]]]],
token_type_match_fallback: bool=False,
use_accepts: bool=True
) -> Optional[T]:

0
lark/py.typed Normal file
View File

View File

@ -9,7 +9,7 @@ __version__ ,= re.findall('__version__: str = "(.*)"', open('lark/__init__.py').
setup(
name = "lark",
version = __version__,
packages = ['lark', 'lark.parsers', 'lark.tools', 'lark.grammars', 'lark.__pyinstaller', 'lark-stubs'],
packages = ['lark', 'lark.parsers', 'lark.tools', 'lark.grammars', 'lark.__pyinstaller'],
requires = [],
install_requires = [],
@ -20,7 +20,7 @@ setup(
"atomic_cache": ["atomicwrites"],
},
package_data = {'': ['*.md', '*.lark'], 'lark-stubs': ['*.pyi']},
package_data = {'': ['*.md', '*.lark'], 'lark': ['py.typed']},
test_suite = 'tests.__main__',