mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 12:54:29 +08:00
Make mypy happy
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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,7 +16,8 @@ _CLOSING_BRACKETS = ')', ']', '}'
|
||||
_FACTOR = '+', '-', '~'
|
||||
_ALLOW_SPACE = '*', '+', '-', '**', '/', '//', '@'
|
||||
_BITWISE_OPERATOR = '<<', '>>', '|', '&', '^'
|
||||
_NEEDS_SPACE = ('=', '%', '->',
|
||||
_NEEDS_SPACE: Tuple[str, ...] = (
|
||||
'=', '%', '->',
|
||||
'<', '>', '==', '>=', '<=', '<>', '!=',
|
||||
'+=', '-=', '*=', '@=', '/=', '%=', '&=', '|=', '^=', '<<=',
|
||||
'>>=', '**=', '//=')
|
||||
|
||||
Reference in New Issue
Block a user