From 224fe934f30ac0cbeb3bae81260008cc302402a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 25 Mar 2022 14:34:41 +0100 Subject: Add basic typing to ``pylint/utils.py`` (#5977) --- pylint/checkers/__init__.py | 2 +- pylint/utils/utils.py | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'pylint') diff --git a/pylint/checkers/__init__.py b/pylint/checkers/__init__.py index 2855d7029..fa14f5eea 100644 --- a/pylint/checkers/__init__.py +++ b/pylint/checkers/__init__.py @@ -67,7 +67,7 @@ def table_lines_from_stats( """ lines: List[str] = [] if stat_type == "duplicated_lines": - new: List[Tuple[str, Union[str, int, float]]] = [ + new: List[Tuple[str, Union[int, float]]] = [ ("nb_duplicated_lines", stats.duplicated_lines["nb_duplicated_lines"]), ( "percent_duplicated_lines", diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py index 6a60cd8e9..bf2cb632d 100644 --- a/pylint/utils/utils.py +++ b/pylint/utils/utils.py @@ -41,6 +41,7 @@ else: if TYPE_CHECKING: from pylint.checkers.base_checker import BaseChecker + from pylint.lint import PyLinter DEFAULT_LINE_LENGTH = 79 @@ -93,11 +94,11 @@ CMPS = ["=", "-", "+"] # py3k has no more cmp builtin -def cmp(a, b): +def cmp(a: Union[int, float], b: Union[int, float]) -> int: return (a > b) - (a < b) -def diff_string(old, new): +def diff_string(old: Union[int, float], new: Union[int, float]) -> str: """Given an old and new int value, return a string representing the difference """ @@ -106,7 +107,7 @@ def diff_string(old, new): return diff_str -def get_module_and_frameid(node): +def get_module_and_frameid(node: nodes.NodeNG) -> Tuple[str, str]: """Return the module name and the frame id in the module.""" frame = node.frame(future=True) module, obj = "", [] @@ -166,7 +167,7 @@ def tokenize_module(node: nodes.Module) -> List[tokenize.TokenInfo]: return list(tokenize.tokenize(readline)) -def register_plugins(linter, directory): +def register_plugins(linter: "PyLinter", directory: str) -> None: """Load all module and package in the given directory, looking for a 'register' function in each one, used to register pylint checkers """ @@ -298,13 +299,10 @@ def _splitstrip(string, sep=","): return [word.strip() for word in string.split(sep) if word.strip()] -def _unquote(string): +def _unquote(string: str) -> str: """Remove optional quotes (simple or double) from the string. - :type string: str or unicode :param string: an optionally quoted string - - :rtype: str or unicode :return: the unquoted string (or the input string if it wasn't quoted) """ if not string: @@ -383,7 +381,7 @@ def _ini_format(stream: TextIO, options: List[Tuple]) -> None: class IsortDriver: """A wrapper around isort API that changed between versions 4 and 5.""" - def __init__(self, config): + def __init__(self, config) -> None: if HAS_ISORT_5: self.isort5_config = isort.api.Config( # There is no typo here. EXTRA_standard_library is @@ -400,7 +398,7 @@ class IsortDriver: known_third_party=config.known_third_party, ) - def place_module(self, package): + def place_module(self, package: str) -> str: if HAS_ISORT_5: return isort.api.place_module(package, self.isort5_config) return self.isort4_obj.place_module(package) -- cgit v1.2.1