summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2022-04-14 22:51:14 +0200
committerGitHub <noreply@github.com>2022-04-14 22:51:14 +0200
commit2e0a4e716f136d86727f903fdeb4b107e471d524 (patch)
treed8e5ab819a3bc637bd27ac36511628da29c9180d
parenta693ea7e1785def007c5a80d379cc7aaf92f38a9 (diff)
downloadpylint-git-2e0a4e716f136d86727f903fdeb4b107e471d524.tar.gz
Add some manual typing changes (#6325)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
-rw-r--r--examples/deprecation_checker.py13
-rw-r--r--pylint/checkers/base/name_checker/naming_style.py4
-rw-r--r--pylint/checkers/variables.py9
-rw-r--r--pylint/lint/parallel.py5
-rw-r--r--pylint/lint/pylinter.py5
-rw-r--r--pylint/lint/report_functions.py4
-rw-r--r--pylint/testutils/functional/test_file.py2
-rw-r--r--pylint/testutils/output_line.py3
-rw-r--r--pylint/utils/file_state.py6
-rw-r--r--pylint/utils/pragma_parser.py2
-rw-r--r--pylint/utils/utils.py13
-rw-r--r--script/bump_changelog.py6
-rw-r--r--script/fix_documentation.py8
-rw-r--r--script/get_unused_message_id_category.py6
14 files changed, 45 insertions, 41 deletions
diff --git a/examples/deprecation_checker.py b/examples/deprecation_checker.py
index 79a728537..db4596096 100644
--- a/examples/deprecation_checker.py
+++ b/examples/deprecation_checker.py
@@ -37,7 +37,10 @@ from module mymodule:
------------------------------------------------------------------
Your code has been rated at 2.00/10 (previous run: 2.00/10, +0.00)
"""
-from typing import TYPE_CHECKING, Set, Tuple, Union
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING
from pylint.checkers import BaseChecker, DeprecatedMixin
from pylint.interfaces import IAstroidChecker
@@ -58,7 +61,7 @@ class DeprecationChecker(DeprecatedMixin, BaseChecker):
# The name defines a custom section of the config for this checker.
name = "deprecated"
- def deprecated_methods(self) -> Set[str]:
+ def deprecated_methods(self) -> set[str]:
"""Callback method called by DeprecatedMixin for every method/function found in the code.
Returns:
@@ -66,9 +69,7 @@ class DeprecationChecker(DeprecatedMixin, BaseChecker):
"""
return {"mymodule.deprecated_function", "mymodule.MyClass.deprecated_method"}
- def deprecated_arguments(
- self, method: str
- ) -> Tuple[Tuple[Union[int, None], str], ...]:
+ def deprecated_arguments(self, method: str) -> tuple[tuple[int | None, str], ...]:
"""Callback returning the deprecated arguments of method/function.
Returns:
@@ -92,5 +93,5 @@ class DeprecationChecker(DeprecatedMixin, BaseChecker):
return ()
-def register(linter: "PyLinter") -> None:
+def register(linter: PyLinter) -> None:
linter.register_checker(DeprecationChecker(linter))
diff --git a/pylint/checkers/base/name_checker/naming_style.py b/pylint/checkers/base/name_checker/naming_style.py
index f3e381c2e..cf20169ec 100644
--- a/pylint/checkers/base/name_checker/naming_style.py
+++ b/pylint/checkers/base/name_checker/naming_style.py
@@ -2,8 +2,10 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
+from __future__ import annotations
+
import re
-from typing import Pattern
+from re import Pattern
from pylint import constants
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py
index 7f476d617..96c8c4dea 100644
--- a/pylint/checkers/variables.py
+++ b/pylint/checkers/variables.py
@@ -12,10 +12,11 @@ import itertools
import os
import re
import sys
+from collections import defaultdict
from collections.abc import Iterable, Iterator
from enum import Enum
from functools import lru_cache
-from typing import TYPE_CHECKING, Any, DefaultDict, NamedTuple
+from typing import TYPE_CHECKING, Any, NamedTuple
import astroid
from astroid import nodes
@@ -516,7 +517,7 @@ class ScopeConsumer(NamedTuple):
to_consume: dict[str, list[nodes.NodeNG]]
consumed: dict[str, list[nodes.NodeNG]]
- consumed_uncertain: DefaultDict[str, list[nodes.NodeNG]]
+ consumed_uncertain: defaultdict[str, list[nodes.NodeNG]]
scope_type: str
@@ -557,7 +558,7 @@ scope_type : {self._atomic.scope_type}
return self._atomic.consumed
@property
- def consumed_uncertain(self) -> DefaultDict[str, list[nodes.NodeNG]]:
+ def consumed_uncertain(self) -> defaultdict[str, list[nodes.NodeNG]]:
"""Retrieves nodes filtered out by get_next_to_consume() that may not
have executed, such as statements in except blocks, or statements
@@ -2698,7 +2699,7 @@ class VariablesChecker(BaseChecker):
def _check_imports(self, not_consumed):
local_names = _fix_dot_imports(not_consumed)
checked = set()
- unused_wildcard_imports: DefaultDict[
+ unused_wildcard_imports: defaultdict[
tuple[str, nodes.ImportFrom], list[str]
] = collections.defaultdict(list)
for name, stmt in local_names:
diff --git a/pylint/lint/parallel.py b/pylint/lint/parallel.py
index d6b8621e2..7f160e328 100644
--- a/pylint/lint/parallel.py
+++ b/pylint/lint/parallel.py
@@ -7,8 +7,9 @@ from __future__ import annotations
import collections
import functools
import warnings
+from collections import defaultdict
from collections.abc import Iterable, Sequence
-from typing import TYPE_CHECKING, Any, DefaultDict
+from typing import TYPE_CHECKING, Any
import dill
@@ -66,7 +67,7 @@ def _worker_initialize(
def _worker_check_single_file(
file_item: FileItem,
) -> tuple[
- int, Any, str, Any, list[tuple[Any, ...]], LinterStats, Any, DefaultDict[Any, list]
+ int, Any, str, Any, list[tuple[Any, ...]], LinterStats, Any, defaultdict[Any, list]
]:
if not _worker_linter:
raise Exception("Worker linter not yet initialised")
diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py
index 8647f6ff2..491a2cf4f 100644
--- a/pylint/lint/pylinter.py
+++ b/pylint/lint/pylinter.py
@@ -13,9 +13,10 @@ import sys
import tokenize
import traceback
import warnings
+from collections import defaultdict
from collections.abc import Iterable, Iterator, Sequence
from io import TextIOWrapper
-from typing import Any, DefaultDict
+from typing import Any
import astroid
from astroid import AstroidError, nodes
@@ -600,7 +601,7 @@ class PyLinter(
"""Dictionary of possible but non-initialized reporters."""
# Attributes for checkers and plugins
- self._checkers: DefaultDict[
+ self._checkers: defaultdict[
str, list[checkers.BaseChecker]
] = collections.defaultdict(list)
"""Dictionary of registered and initialized checkers."""
diff --git a/pylint/lint/report_functions.py b/pylint/lint/report_functions.py
index e32406200..6690ce343 100644
--- a/pylint/lint/report_functions.py
+++ b/pylint/lint/report_functions.py
@@ -5,7 +5,7 @@
from __future__ import annotations
import collections
-from typing import DefaultDict
+from collections import defaultdict
from pylint import checkers, exceptions
from pylint.reporters.ureports.nodes import Table
@@ -52,7 +52,7 @@ def report_messages_by_module_stats(
if len(module_stats) == 1:
# don't print this report when we are analysing a single module
raise exceptions.EmptyReportError()
- by_mod: DefaultDict[str, dict[str, int | float]] = collections.defaultdict(dict)
+ by_mod: defaultdict[str, dict[str, int | float]] = collections.defaultdict(dict)
for m_type in ("fatal", "error", "warning", "refactor", "convention"):
total = stats.get_global_message_count(m_type)
for module in module_stats.keys():
diff --git a/pylint/testutils/functional/test_file.py b/pylint/testutils/functional/test_file.py
index 45ffca5a5..a27f344e8 100644
--- a/pylint/testutils/functional/test_file.py
+++ b/pylint/testutils/functional/test_file.py
@@ -6,8 +6,8 @@ from __future__ import annotations
import configparser
import sys
+from collections.abc import Callable
from os.path import basename, exists, join
-from typing import Callable
def parse_python_version(ver_str: str) -> tuple[int, ...]:
diff --git a/pylint/testutils/output_line.py b/pylint/testutils/output_line.py
index 139478908..4cde92d4f 100644
--- a/pylint/testutils/output_line.py
+++ b/pylint/testutils/output_line.py
@@ -5,7 +5,8 @@
from __future__ import annotations
import warnings
-from typing import Any, NamedTuple, Sequence, TypeVar
+from collections.abc import Sequence
+from typing import Any, NamedTuple, TypeVar
from astroid import nodes
diff --git a/pylint/utils/file_state.py b/pylint/utils/file_state.py
index 7050e72fc..02b94b379 100644
--- a/pylint/utils/file_state.py
+++ b/pylint/utils/file_state.py
@@ -6,7 +6,9 @@ from __future__ import annotations
import collections
import sys
-from typing import TYPE_CHECKING, DefaultDict, Dict, Iterator
+from collections import defaultdict
+from collections.abc import Iterator
+from typing import TYPE_CHECKING, Dict
from astroid import nodes
@@ -35,7 +37,7 @@ class FileState:
self.base_name = modname
self._module_msgs_state: MessageStateDict = {}
self._raw_module_msgs_state: MessageStateDict = {}
- self._ignored_msgs: DefaultDict[
+ self._ignored_msgs: defaultdict[
tuple[str, int], set[int]
] = collections.defaultdict(set)
self._suppression_mapping: dict[tuple[str, int], int] = {}
diff --git a/pylint/utils/pragma_parser.py b/pylint/utils/pragma_parser.py
index 4317b27c8..341705571 100644
--- a/pylint/utils/pragma_parser.py
+++ b/pylint/utils/pragma_parser.py
@@ -6,7 +6,7 @@ from __future__ import annotations
import re
from collections import namedtuple
-from typing import Generator
+from collections.abc import Generator
# Allow stopping after the first semicolon/hash encountered,
# so that an option can be continued with the reasons
diff --git a/pylint/utils/utils.py b/pylint/utils/utils.py
index 11c82cd58..0214d3fac 100644
--- a/pylint/utils/utils.py
+++ b/pylint/utils/utils.py
@@ -21,18 +21,9 @@ import sys
import textwrap
import tokenize
import warnings
+from collections.abc import Sequence
from io import BufferedReader, BytesIO
-from typing import (
- TYPE_CHECKING,
- List,
- Pattern,
- Sequence,
- TextIO,
- Tuple,
- TypeVar,
- Union,
- overload,
-)
+from typing import TYPE_CHECKING, List, Pattern, TextIO, Tuple, TypeVar, Union, overload
from astroid import Module, modutils, nodes
diff --git a/script/bump_changelog.py b/script/bump_changelog.py
index f1edcdbb0..fca874699 100644
--- a/script/bump_changelog.py
+++ b/script/bump_changelog.py
@@ -7,12 +7,14 @@
"""This script permits to upgrade the changelog in astroid or pylint when releasing a version."""
# pylint: disable=logging-fstring-interpolation
+
+from __future__ import annotations
+
import argparse
import enum
import logging
from datetime import datetime
from pathlib import Path
-from typing import List
DEFAULT_CHANGELOG_PATH = Path("ChangeLog")
@@ -59,7 +61,7 @@ def get_next_version(version: str, version_type: VersionType) -> str:
return ".".join(new_version)
-def get_next_versions(version: str, version_type: VersionType) -> List[str]:
+def get_next_versions(version: str, version_type: VersionType) -> list[str]:
if version_type == VersionType.PATCH:
# "2.6.1" => ["2.6.2"]
diff --git a/script/fix_documentation.py b/script/fix_documentation.py
index 24dd0097e..e248f0646 100644
--- a/script/fix_documentation.py
+++ b/script/fix_documentation.py
@@ -3,10 +3,12 @@
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
"""Small script to fix various issues with the documentation. Used by pre-commit."""
+
+from __future__ import annotations
+
import argparse
import re
import sys
-from typing import List, Optional, Union
INVALID_CODE_BLOCK_PATTERN = (
r"(?<=\s`)([\w\-\.\(\)\=]+\s{0,1}[\w\-\.\(\)\=]*)(?=`[,\.]{0,1}\s|$)"
@@ -50,7 +52,7 @@ class CustomHelpFormatter(argparse.HelpFormatter):
prog: str,
indent_increment: int = 2,
max_help_position: int = 24,
- width: Optional[int] = None,
+ width: int | None = None,
) -> None:
max_help_position = 40
super().__init__(
@@ -61,7 +63,7 @@ class CustomHelpFormatter(argparse.HelpFormatter):
)
-def main(argv: Union[List[str], None] = None) -> int:
+def main(argv: list[str] | None = None) -> int:
argv = argv or sys.argv[1:]
parser = argparse.ArgumentParser(formatter_class=CustomHelpFormatter)
parser.add_argument(
diff --git a/script/get_unused_message_id_category.py b/script/get_unused_message_id_category.py
index 7bf1a1343..a344ba145 100644
--- a/script/get_unused_message_id_category.py
+++ b/script/get_unused_message_id_category.py
@@ -3,7 +3,7 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
-from typing import List
+from __future__ import annotations
from pylint.checkers import initialize as initialize_checkers
from pylint.constants import DELETED_MSGID_PREFIXES
@@ -11,14 +11,14 @@ from pylint.extensions import initialize as initialize_extensions
from pylint.lint.pylinter import PyLinter
-def register_all_checkers_and_plugins(linter: "PyLinter") -> None:
+def register_all_checkers_and_plugins(linter: PyLinter) -> None:
"""Registers all checkers and plugins."""
linter.cmdline_parser.set_conflict_handler("resolve")
initialize_checkers(linter)
initialize_extensions(linter)
-def get_next_code_category(message_ids: List[str]) -> int:
+def get_next_code_category(message_ids: list[str]) -> int:
categories = sorted({int(i[:2]) for i in message_ids})
# We add the prefixes for deleted checkers
categories += DELETED_MSGID_PREFIXES