From 2b2d1b564349c0736e9b110926376b1282159df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 14 Apr 2022 09:42:35 +0200 Subject: [PATCH] Use ``python-typing-update`` on ``pylint`` directory --- pylint/__init__.py | 12 +++++++----- pylint/__pkginfo__.py | 4 ++-- pylint/constants.py | 12 +++++++----- pylint/epylint.py | 7 +++++-- pylint/graph.py | 6 ++++-- pylint/interfaces.py | 11 +++++++---- pylint/typing.py | 14 ++++++++------ 7 files changed, 40 insertions(+), 26 deletions(-) diff --git a/pylint/__init__.py b/pylint/__init__.py index 9fde923dc0..0b3b7e594e 100644 --- a/pylint/__init__.py +++ b/pylint/__init__.py @@ -2,16 +2,18 @@ # 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 os import sys -from typing import Optional, Sequence +from typing import Sequence from pylint.__pkginfo__ import __version__ # pylint: disable=import-outside-toplevel -def run_pylint(argv: Optional[Sequence[str]] = None): +def run_pylint(argv: Sequence[str] | None = None): """Run pylint. argv can be a sequence of strings normally supplied as arguments on the command line @@ -24,7 +26,7 @@ def run_pylint(argv: Optional[Sequence[str]] = None): sys.exit(1) -def run_epylint(argv: Optional[Sequence[str]] = None): +def run_epylint(argv: Sequence[str] | None = None): """Run epylint. argv can be a list of strings normally supplied as arguments on the command line @@ -34,7 +36,7 @@ def run_epylint(argv: Optional[Sequence[str]] = None): EpylintRun(argv) -def run_pyreverse(argv: Optional[Sequence[str]] = None): +def run_pyreverse(argv: Sequence[str] | None = None): """Run pyreverse. argv can be a sequence of strings normally supplied as arguments on the command line @@ -44,7 +46,7 @@ def run_pyreverse(argv: Optional[Sequence[str]] = None): PyreverseRun(argv or sys.argv[1:]) -def run_symilar(argv: Optional[Sequence[str]] = None): +def run_symilar(argv: Sequence[str] | None = None): """Run symilar. argv can be a sequence of strings normally supplied as arguments on the command line diff --git a/pylint/__pkginfo__.py b/pylint/__pkginfo__.py index 55b0f88187..9c4661dc04 100644 --- a/pylint/__pkginfo__.py +++ b/pylint/__pkginfo__.py @@ -2,12 +2,12 @@ # For details: https://github.com/PyCQA/pylint/blob/main/LICENSE # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt -from typing import Tuple +from __future__ import annotations __version__ = "2.14.0-dev0" -def get_numversion_from_version(v: str) -> Tuple: +def get_numversion_from_version(v: str) -> tuple: """Kept for compatibility reason. See https://github.com/PyCQA/pylint/issues/4399 diff --git a/pylint/constants.py b/pylint/constants.py index d2387a3350..ade139bfbf 100644 --- a/pylint/constants.py +++ b/pylint/constants.py @@ -2,10 +2,12 @@ # 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 os import platform import sys -from typing import Dict, List, NamedTuple, Tuple +from typing import NamedTuple import astroid import platformdirs @@ -28,7 +30,7 @@ # The line/node distinction does not apply to fatal errors and reports. _SCOPE_EXEMPT = "FR" -MSG_TYPES: Dict[str, MessageTypesFullName] = { +MSG_TYPES: dict[str, MessageTypesFullName] = { "I": "info", "C": "convention", "R": "refactor", @@ -36,7 +38,7 @@ "E": "error", "F": "fatal", } -MSG_TYPES_LONG: Dict[str, str] = {v: k for k, v in MSG_TYPES.items()} +MSG_TYPES_LONG: dict[str, str] = {v: k for k, v in MSG_TYPES.items()} MSG_TYPES_STATUS = {"I": 0, "C": 16, "R": 8, "W": 4, "E": 2, "F": 1} @@ -81,10 +83,10 @@ class WarningScope: class DeletedMessage(NamedTuple): msgid: str symbol: str - old_names: List[Tuple[str, str]] = [] + old_names: list[tuple[str, str]] = [] -DELETED_MSGID_PREFIXES: List[int] = [] +DELETED_MSGID_PREFIXES: list[int] = [] DELETED_MESSAGES = [ # Everything until the next comment is from the diff --git a/pylint/epylint.py b/pylint/epylint.py index 2eade40f9b..16fd223561 100755 --- a/pylint/epylint.py +++ b/pylint/epylint.py @@ -36,12 +36,15 @@ You may also use py_run to run pylint with desired options and get back (or not) its output. """ + +from __future__ import annotations + import os import shlex import sys from io import StringIO from subprocess import PIPE, Popen -from typing import Optional, Sequence +from typing import Sequence def _get_env(): @@ -164,7 +167,7 @@ def py_run(command_options="", return_std=False, stdout=None, stderr=None): return None -def Run(argv: Optional[Sequence[str]] = None): +def Run(argv: Sequence[str] | None = None): if not argv and len(sys.argv) == 1: print(f"Usage: {sys.argv[0]} [options]") sys.exit(1) diff --git a/pylint/graph.py b/pylint/graph.py index 8191847249..a8effb65b3 100644 --- a/pylint/graph.py +++ b/pylint/graph.py @@ -6,13 +6,15 @@ (dot generation adapted from pypy/translator/tool/make_dot.py) """ + +from __future__ import annotations + import codecs import os import shutil import subprocess import sys import tempfile -from typing import Optional def target_info_from_filename(filename): @@ -70,7 +72,7 @@ def get_source(self): source = property(get_source) def generate( - self, outputfile: Optional[str] = None, mapfile: Optional[str] = None + self, outputfile: str | None = None, mapfile: str | None = None ) -> str: """Generates a graph file. diff --git a/pylint/interfaces.py b/pylint/interfaces.py index 661525baca..fe1320b8a9 100644 --- a/pylint/interfaces.py +++ b/pylint/interfaces.py @@ -3,8 +3,11 @@ # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt """Interfaces for Pylint objects.""" + +from __future__ import annotations + from collections import namedtuple -from typing import TYPE_CHECKING, Tuple, Type, Union +from typing import TYPE_CHECKING from astroid import nodes @@ -52,8 +55,8 @@ def is_implemented_by(cls, instance): def implements( - obj: "BaseChecker", - interface: Union[Type["Interface"], Tuple[Type["Interface"], ...]], + obj: BaseChecker, + interface: type[Interface] | tuple[type[Interface], ...], ) -> bool: """Does the given object (maybe an instance or class) implement the interface.""" implements_ = getattr(obj, "__implements__", ()) @@ -104,5 +107,5 @@ class IReporter(Interface): def handle_message(self, msg) -> None: """Handle the given message object.""" - def display_reports(self, layout: "Section") -> None: + def display_reports(self, layout: Section) -> None: """Display results encapsulated in the layout tree.""" diff --git a/pylint/typing.py b/pylint/typing.py index a1e4e5c0fa..596b62801d 100644 --- a/pylint/typing.py +++ b/pylint/typing.py @@ -3,6 +3,9 @@ # Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt """A collection of typing utilities.""" + +from __future__ import annotations + import sys from typing import ( TYPE_CHECKING, @@ -11,7 +14,6 @@ Dict, Iterable, NamedTuple, - Optional, Pattern, Tuple, Type, @@ -56,7 +58,7 @@ class ErrorDescriptionDict(TypedDict): key: Literal["fatal"] mod: str - ex: Union[ImportError, SyntaxError] + ex: ImportError | SyntaxError class MessageLocationTuple(NamedTuple): @@ -68,17 +70,17 @@ class MessageLocationTuple(NamedTuple): obj: str line: int column: int - end_line: Optional[int] = None - end_column: Optional[int] = None + end_line: int | None = None + end_column: int | None = None class ManagedMessage(NamedTuple): """Tuple with information about a managed message of the linter.""" - name: Optional[str] + name: str | None msgid: str symbol: str - line: Optional[int] + line: int | None is_disabled: bool