summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/exts/pylint_messages.py16
-rw-r--r--doc/test_messages_documentation.py16
-rw-r--r--examples/custom.py4
-rw-r--r--examples/custom_raw.py4
-rw-r--r--pylint/checkers/classes/class_checker.py2
5 files changed, 25 insertions, 17 deletions
diff --git a/doc/exts/pylint_messages.py b/doc/exts/pylint_messages.py
index 1e7440f87..12b6822fd 100644
--- a/doc/exts/pylint_messages.py
+++ b/doc/exts/pylint_messages.py
@@ -4,12 +4,14 @@
"""Script used to generate the messages files."""
+from __future__ import annotations
+
import os
from collections import defaultdict
from inspect import getmodule
from itertools import chain, groupby
from pathlib import Path
-from typing import DefaultDict, Dict, List, NamedTuple, Optional, Tuple
+from typing import DefaultDict, Dict, List, NamedTuple, Tuple
from sphinx.application import Sphinx
@@ -60,7 +62,7 @@ def _register_all_checkers_and_extensions(linter: PyLinter) -> None:
initialize_extensions(linter)
-def _get_message_data(data_path: Path) -> Tuple[str, str, str, str]:
+def _get_message_data(data_path: Path) -> tuple[str, str, str, str]:
"""Get the message data from the specified path."""
good_py_path = data_path / "good.py"
bad_py_path = data_path / "bad.py"
@@ -145,7 +147,7 @@ You can help us make the doc better `by contributing <https://github.com/PyCQA/p
def _get_all_messages(
linter: PyLinter,
-) -> Tuple[MessagesDict, OldMessagesDict]:
+) -> tuple[MessagesDict, OldMessagesDict]:
"""Get all messages registered to a linter and return a dictionary indexed by
message type.
@@ -305,7 +307,7 @@ def _generate_checker_url(message: MessageData) -> str:
def _write_single_shared_message_page(
- category_dir: Path, messages: List[MessageData]
+ category_dir: Path, messages: list[MessageData]
) -> None:
message = messages[0]
with open(category_dir / f"{message.name}.rst", "w", encoding="utf-8") as stream:
@@ -405,8 +407,8 @@ def _write_redirect_pages(old_messages: OldMessagesDict) -> None:
def _write_redirect_old_page(
category_dir: Path,
- old_name: Tuple[str, str],
- new_names: List[Tuple[str, str]],
+ old_name: tuple[str, str],
+ new_names: list[tuple[str, str]],
) -> None:
old_name_file = os.path.join(category_dir, f"{old_name[0]}.rst")
new_names_string = "".join(
@@ -428,7 +430,7 @@ def _write_redirect_old_page(
# pylint: disable-next=unused-argument
-def build_messages_pages(app: Optional[Sphinx]) -> None:
+def build_messages_pages(app: Sphinx | None) -> None:
"""Overwrite messages files by printing the documentation to a stream.
Documentation is written in ReST format.
diff --git a/doc/test_messages_documentation.py b/doc/test_messages_documentation.py
index 663fa3aab..fad79256b 100644
--- a/doc/test_messages_documentation.py
+++ b/doc/test_messages_documentation.py
@@ -4,6 +4,8 @@
"""Functional tests for the code examples in the messages' documentation."""
+from __future__ import annotations
+
import sys
if sys.version_info[:2] > (3, 9):
@@ -18,7 +20,7 @@ else:
from pathlib import Path
from typing import Counter as CounterType
-from typing import List, Optional, TextIO, Tuple
+from typing import TextIO, Tuple
import pytest
@@ -32,12 +34,12 @@ from pylint.testutils.reporter_for_tests import FunctionalTestReporter
MessageCounter = CounterType[Tuple[int, str]]
-def get_functional_test_files_from_directory(input_dir: Path) -> List[Tuple[str, Path]]:
+def get_functional_test_files_from_directory(input_dir: Path) -> list[tuple[str, Path]]:
"""Get all functional tests in the input_dir.
This also checks the formatting of related.rst files.
"""
- suite: List[Tuple[str, Path]] = []
+ suite: list[tuple[str, Path]] = []
for subdirectory in input_dir.iterdir():
for message_dir in subdirectory.iterdir():
@@ -69,7 +71,7 @@ TESTS_NAMES = [f"{t[0]}-{t[1].stem}" for t in TESTS]
class LintModuleTest:
- def __init__(self, test_file: Tuple[str, Path]) -> None:
+ def __init__(self, test_file: tuple[str, Path]) -> None:
self._test_file = test_file
_test_reporter = FunctionalTestReporter()
@@ -80,7 +82,7 @@ class LintModuleTest:
# Check if this message has a custom configuration file (e.g. for enabling optional checkers).
# If not, use the default configuration.
- config_file: Optional[Path]
+ config_file: Path | None
msgid, full_path = test_file
pylintrc = full_path.parent / "pylintrc"
config_file = pylintrc if pylintrc.exists() else None
@@ -136,7 +138,7 @@ class LintModuleTest:
def _get_actual(self) -> MessageCounter:
"""Get the actual messages after a run."""
- messages: List[Message] = self._linter.reporter.messages
+ messages: list[Message] = self._linter.reporter.messages
messages.sort(key=lambda m: (m.line, m.symbol, m.msg))
received_msgs: MessageCounter = Counter()
for msg in messages:
@@ -176,6 +178,6 @@ See:
@pytest.mark.parametrize("test_file", TESTS, ids=TESTS_NAMES)
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
-def test_code_examples(test_file: Tuple[str, Path]) -> None:
+def test_code_examples(test_file: tuple[str, Path]) -> None:
lint_test = LintModuleTest(test_file)
lint_test.runTest()
diff --git a/examples/custom.py b/examples/custom.py
index 003519a56..9f22434d8 100644
--- a/examples/custom.py
+++ b/examples/custom.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
from typing import TYPE_CHECKING
from astroid import nodes
@@ -59,7 +61,7 @@ class MyAstroidChecker(BaseChecker):
in_class.locals[param.name] = node
-def register(linter: "PyLinter") -> None:
+def register(linter: PyLinter) -> None:
"""This required method auto registers the checker during initialization.
:param linter: The linter to register the checker to.
diff --git a/examples/custom_raw.py b/examples/custom_raw.py
index 090f87ea8..68e685504 100644
--- a/examples/custom_raw.py
+++ b/examples/custom_raw.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
from typing import TYPE_CHECKING
from astroid import nodes
@@ -37,7 +39,7 @@ class MyRawChecker(BaseRawFileChecker):
self.add_message("backslash-line-continuation", line=lineno)
-def register(linter: "PyLinter") -> None:
+def register(linter: PyLinter) -> None:
"""This required method auto registers the checker during initialization.
:param linter: The linter to register the checker to.
diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py
index cf2fc39e2..e66e543f2 100644
--- a/pylint/checkers/classes/class_checker.py
+++ b/pylint/checkers/classes/class_checker.py
@@ -1161,7 +1161,7 @@ a metaclass class method.",
self._check_property_with_parameters(node)
# 'is_method()' is called and makes sure that this is a 'nodes.ClassDef'
- klass = node.parent.frame(future=True) # type: nodes.ClassDef
+ klass: nodes.ClassDef = node.parent.frame(future=True)
# check first argument is self if this is actually a method
self._check_first_arg_for_type(node, klass.type == "metaclass")
if node.name == "__init__":