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 warnings
import pickle
from typing import Dict, Any
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"))
parser_cache = {}
parser_cache: Dict[str, Any] = {}
class _NodeCacheItem(object):

View File

@@ -1,4 +1,5 @@
from contextlib import contextmanager
from typing import Dict, List
class _NormalizerMeta(type):
@@ -10,8 +11,8 @@ class _NormalizerMeta(type):
class Normalizer(metaclass=_NormalizerMeta):
_rule_type_instances = {}
_rule_value_instances = {}
_rule_type_instances: Dict[str, List[type]] = {}
_rule_value_instances: Dict[str, List[type]] = {}
def __init__(self, grammar, config):
self.grammar = grammar
@@ -75,7 +76,7 @@ class Normalizer(metaclass=_NormalizerMeta):
return True
@classmethod
def register_rule(cls, **kwargs):
def register_rule(cls, *, value=None, values=(), type=None, types=()):
"""
Use it as a class decorator::
@@ -84,10 +85,6 @@ class Normalizer(metaclass=_NormalizerMeta):
class MyRule(Rule):
error_code = 42
"""
return cls._register_rule(**kwargs)
@classmethod
def _register_rule(cls, value=None, values=(), type=None, types=()):
values = list(values)
types = list(types)
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
``Statement``, which produces ``Array`` and ``Call``).
"""
from typing import Dict
from parso import tree
from parso.pgen2.generator import ReservedString
@@ -108,11 +110,10 @@ class BaseParser(object):
When a syntax error occurs, error_recovery() is called.
"""
node_map = {}
node_map: Dict[str, type] = {}
default_node = tree.Node
leaf_map = {
}
leaf_map: Dict[str, type] = {}
default_leaf = tree.Leaf
def __init__(self, pgen_grammar, start_nonterminal='file_input', error_recovery=False):

View File

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