Skip to content

Commit

Permalink
Use python-typing-update on pylint directory
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Apr 14, 2022
1 parent 01676ae commit 2b2d1b5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 26 deletions.
12 changes: 7 additions & 5 deletions pylint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pylint/__pkginfo__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions pylint/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,15 +30,15 @@
# 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",
"W": "warning",
"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}

Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pylint/epylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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]} <filename> [options]")
sys.exit(1)
Expand Down
6 changes: 4 additions & 2 deletions pylint/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 7 additions & 4 deletions pylint/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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__", ())
Expand Down Expand Up @@ -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."""
14 changes: 8 additions & 6 deletions pylint/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -11,7 +14,6 @@
Dict,
Iterable,
NamedTuple,
Optional,
Pattern,
Tuple,
Type,
Expand Down Expand Up @@ -56,7 +58,7 @@ class ErrorDescriptionDict(TypedDict):

key: Literal["fatal"]
mod: str
ex: Union[ImportError, SyntaxError]
ex: ImportError | SyntaxError


class MessageLocationTuple(NamedTuple):
Expand All @@ -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


Expand Down

0 comments on commit 2b2d1b5

Please sign in to comment.