diff options
Diffstat (limited to 'pyparsing/util.py')
-rw-r--r-- | pyparsing/util.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/pyparsing/util.py b/pyparsing/util.py index 95ecff3..1309ad6 100644 --- a/pyparsing/util.py +++ b/pyparsing/util.py @@ -38,7 +38,7 @@ class __config_flags: @lru_cache(maxsize=128) -def col(loc: int, strg: str): +def col(loc: int, strg: str) -> int: """ Returns current column within a string, counting newlines as line separators. The first column is number 1. @@ -55,7 +55,7 @@ def col(loc: int, strg: str): @lru_cache(maxsize=128) -def lineno(loc: int, strg: str): +def lineno(loc: int, strg: str) -> int: """Returns current line number within a string, counting newlines as line separators. The first line is number 1. @@ -69,7 +69,7 @@ def lineno(loc: int, strg: str): @lru_cache(maxsize=128) -def line(loc: int, strg: str): +def line(loc: int, strg: str) -> str: """ Returns the line of text containing loc within a string, counting newlines as line separators. """ @@ -84,18 +84,18 @@ class _UnboundedCache: cache_get = cache.get self.not_in_cache = not_in_cache = object() - def get(self, key): + def get(_, key): return cache_get(key, not_in_cache) - def set(self, key, value): + def set_(_, key, value): cache[key] = value - def clear(self): + def clear(_): cache.clear() self.size = None self.get = types.MethodType(get, self) - self.set = types.MethodType(set, self) + self.set = types.MethodType(set_, self) self.clear = types.MethodType(clear, self) @@ -105,20 +105,20 @@ class _FifoCache: cache = collections.OrderedDict() cache_get = cache.get - def get(self, key): + def get(_, key): return cache_get(key, not_in_cache) - def set(self, key, value): + def set_(_, key, value): cache[key] = value while len(cache) > size: cache.popitem(last=False) - def clear(self): + def clear(_): cache.clear() self.size = size self.get = types.MethodType(get, self) - self.set = types.MethodType(set, self) + self.set = types.MethodType(set_, self) self.clear = types.MethodType(clear, self) @@ -170,7 +170,7 @@ class UnboundedMemo(dict): pass -def _escape_regex_range_chars(s: str): +def _escape_regex_range_chars(s: str) -> str: # escape these chars: ^-[] for c in r"\^-[]": s = s.replace(c, _bslash + c) @@ -179,7 +179,9 @@ def _escape_regex_range_chars(s: str): return str(s) -def _collapse_string_to_ranges(s: Union[str, Iterable[str]], re_escape: bool = True): +def _collapse_string_to_ranges( + s: Union[str, Iterable[str]], re_escape: bool = True +) -> str: def is_consecutive(c): c_int = ord(c) is_consecutive.prev, prev = c_int, is_consecutive.prev @@ -222,7 +224,7 @@ def _collapse_string_to_ranges(s: Union[str, Iterable[str]], re_escape: bool = T return "".join(ret) -def _flatten(ll: List): +def _flatten(ll: list) -> list: ret = [] for i in ll: if isinstance(i, list): |