Make mypy happy

This commit is contained in:
Dave Halter
2020-07-25 15:43:28 +02:00
parent 8a34245239
commit 67904f4d24
4 changed files with 16 additions and 15 deletions

View File

@@ -8,6 +8,7 @@ import platform
import logging import logging
import warnings import warnings
import pickle import pickle
from typing import Dict, Any
from parso.file_io import FileIO from parso.file_io import FileIO
@@ -98,7 +99,7 @@ def _get_cache_clear_lock(cache_path=None):
return FileIO(os.path.join(cache_path, "PARSO-CACHE-LOCK")) return FileIO(os.path.join(cache_path, "PARSO-CACHE-LOCK"))
parser_cache = {} parser_cache: Dict[str, Any] = {}
class _NodeCacheItem(object): class _NodeCacheItem(object):

View File

@@ -1,4 +1,5 @@
from contextlib import contextmanager from contextlib import contextmanager
from typing import Dict, List
class _NormalizerMeta(type): class _NormalizerMeta(type):
@@ -10,8 +11,8 @@ class _NormalizerMeta(type):
class Normalizer(metaclass=_NormalizerMeta): class Normalizer(metaclass=_NormalizerMeta):
_rule_type_instances = {} _rule_type_instances: Dict[str, List[type]] = {}
_rule_value_instances = {} _rule_value_instances: Dict[str, List[type]] = {}
def __init__(self, grammar, config): def __init__(self, grammar, config):
self.grammar = grammar self.grammar = grammar
@@ -75,7 +76,7 @@ class Normalizer(metaclass=_NormalizerMeta):
return True return True
@classmethod @classmethod
def register_rule(cls, **kwargs): def register_rule(cls, *, value=None, values=(), type=None, types=()):
""" """
Use it as a class decorator:: Use it as a class decorator::
@@ -84,10 +85,6 @@ class Normalizer(metaclass=_NormalizerMeta):
class MyRule(Rule): class MyRule(Rule):
error_code = 42 error_code = 42
""" """
return cls._register_rule(**kwargs)
@classmethod
def _register_rule(cls, value=None, values=(), type=None, types=()):
values = list(values) values = list(values)
types = list(types) types = list(types)
if value is not None: if value is not None:

View File

@@ -23,6 +23,8 @@ within the statement. This lowers memory usage and cpu time and reduces the
complexity of the ``Parser`` (there's another parser sitting inside complexity of the ``Parser`` (there's another parser sitting inside
``Statement``, which produces ``Array`` and ``Call``). ``Statement``, which produces ``Array`` and ``Call``).
""" """
from typing import Dict
from parso import tree from parso import tree
from parso.pgen2.generator import ReservedString from parso.pgen2.generator import ReservedString
@@ -108,11 +110,10 @@ class BaseParser(object):
When a syntax error occurs, error_recovery() is called. When a syntax error occurs, error_recovery() is called.
""" """
node_map = {} node_map: Dict[str, type] = {}
default_node = tree.Node default_node = tree.Node
leaf_map = { leaf_map: Dict[str, type] = {}
}
default_leaf = tree.Leaf default_leaf = tree.Leaf
def __init__(self, pgen_grammar, start_nonterminal='file_input', error_recovery=False): def __init__(self, pgen_grammar, start_nonterminal='file_input', error_recovery=False):

View File

@@ -1,5 +1,6 @@
import re import re
from contextlib import contextmanager from contextlib import contextmanager
from typing import Tuple
from parso.python.errors import ErrorFinder, ErrorFinderConfig from parso.python.errors import ErrorFinder, ErrorFinderConfig
from parso.normalizer import Rule from parso.normalizer import Rule
@@ -15,7 +16,8 @@ _CLOSING_BRACKETS = ')', ']', '}'
_FACTOR = '+', '-', '~' _FACTOR = '+', '-', '~'
_ALLOW_SPACE = '*', '+', '-', '**', '/', '//', '@' _ALLOW_SPACE = '*', '+', '-', '**', '/', '//', '@'
_BITWISE_OPERATOR = '<<', '>>', '|', '&', '^' _BITWISE_OPERATOR = '<<', '>>', '|', '&', '^'
_NEEDS_SPACE = ('=', '%', '->', _NEEDS_SPACE: Tuple[str, ...] = (
'=', '%', '->',
'<', '>', '==', '>=', '<=', '<>', '!=', '<', '>', '==', '>=', '<=', '<>', '!=',
'+=', '-=', '*=', '@=', '/=', '%=', '&=', '|=', '^=', '<<=', '+=', '-=', '*=', '@=', '/=', '%=', '&=', '|=', '^=', '<<=',
'>>=', '**=', '//=') '>>=', '**=', '//=')