Coverage for C:\Repos\ekr-pylint\pylint\typing.py: 92%
52 statements
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
« prev ^ index » next coverage.py v6.4, created at 2022-05-24 10:21 -0500
1# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
2# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
3# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
5"""A collection of typing utilities."""
7from __future__ import annotations
9import sys
10from typing import (
11 TYPE_CHECKING,
12 Any,
13 Callable,
14 Dict,
15 Iterable,
16 NamedTuple,
17 Optional,
18 Pattern,
19 Tuple,
20 Type,
21 Union,
22)
24if sys.version_info >= (3, 8):
25 from typing import Literal, TypedDict
26else:
27 from typing_extensions import Literal, TypedDict
29if TYPE_CHECKING:
30 from pylint.config.callback_actions import _CallbackAction
31 from pylint.reporters.ureports.nodes import Section
32 from pylint.utils import LinterStats
35class FileItem(NamedTuple):
36 """Represents data about a file handled by pylint.
38 Each file item has:
39 - name: full name of the module
40 - filepath: path of the file
41 - modname: module name
42 """
44 name: str
45 filepath: str
46 modpath: str
49class ModuleDescriptionDict(TypedDict):
50 """Represents data about a checked module."""
52 path: str
53 name: str
54 isarg: bool
55 basepath: str
56 basename: str
59class ErrorDescriptionDict(TypedDict):
60 """Represents data about errors collected during checking of a module."""
62 key: Literal["fatal"]
63 mod: str
64 ex: ImportError | SyntaxError
67class MessageLocationTuple(NamedTuple):
68 """Tuple with information about the location of a to-be-displayed message."""
70 abspath: str
71 path: str
72 module: str
73 obj: str
74 line: int
75 column: int
76 end_line: int | None = None
77 end_column: int | None = None
80class ManagedMessage(NamedTuple):
81 """Tuple with information about a managed message of the linter."""
83 name: str | None
84 msgid: str
85 symbol: str
86 line: int | None
87 is_disabled: bool
90MessageTypesFullName = Literal[
91 "convention", "error", "fatal", "info", "refactor", "statement", "warning"
92]
93"""All possible message categories."""
96OptionDict = Dict[
97 str,
98 Union[
99 None,
100 str,
101 bool,
102 int,
103 Pattern[str],
104 Iterable[Union[str, int, Pattern[str]]],
105 Type["_CallbackAction"],
106 Callable[[Any], Any],
107 Callable[[Any, Any, Any, Any], Any],
108 ],
109]
110Options = Tuple[Tuple[str, OptionDict], ...]
113ReportsCallable = Callable[["Section", "LinterStats", Optional["LinterStats"]], None]
114"""Callable to create a report."""
117class ExtraMessageOptions(TypedDict, total=False):
118 """All allowed keys in the extra options for message definitions."""
120 scope: str
121 old_names: list[tuple[str, str]]
122 maxversion: tuple[int, int]
123 minversion: tuple[int, int]
126MessageDefinitionTuple = Union[
127 Tuple[str, str, str],
128 Tuple[str, str, str, ExtraMessageOptions],
129]