From 887668b96b3ffe40ac4ab5fc71a0ea093ee66c11 Mon Sep 17 00:00:00 2001 From: correctmost <134317971+correctmost@users.noreply.github.com> Date: Sat, 7 Sep 2024 02:37:50 -0400 Subject: [PATCH] Fix additional mypy errors and expand CI checks to more files (#2541) * Fix additional mypy errors and expand CI checks to more files * Use an assertion instead of a type ignore * Move an assert outside of a type-checking block --- astroid/_ast.py | 2 +- astroid/brain/brain_argparse.py | 3 +- astroid/brain/brain_boto3.py | 6 ++-- astroid/brain/brain_builtin_inference.py | 9 ++--- astroid/brain/brain_crypt.py | 3 +- astroid/brain/brain_ctypes.py | 3 +- astroid/brain/brain_curses.py | 3 +- astroid/brain/brain_datetime.py | 3 +- astroid/brain/brain_dateutil.py | 3 +- astroid/brain/brain_functools.py | 3 +- astroid/brain/brain_hashlib.py | 3 +- astroid/brain/brain_http.py | 5 +-- astroid/brain/brain_hypothesis.py | 5 +-- astroid/brain/brain_namedtuple_enum.py | 3 +- astroid/brain/brain_numpy_core_fromnumeric.py | 3 +- astroid/brain/brain_numpy_core_multiarray.py | 3 +- astroid/brain/brain_numpy_core_numeric.py | 3 +- .../brain/brain_numpy_core_numerictypes.py | 3 +- astroid/brain/brain_numpy_core_umath.py | 3 +- astroid/brain/brain_numpy_ma.py | 3 +- astroid/brain/brain_numpy_random_mtrand.py | 3 +- astroid/brain/brain_pathlib.py | 3 +- astroid/brain/brain_pkg_resources.py | 5 +-- astroid/brain/brain_pytest.py | 3 +- astroid/brain/brain_qt.py | 4 +-- astroid/brain/brain_re.py | 3 +- astroid/brain/brain_regex.py | 3 +- astroid/brain/brain_responses.py | 3 +- astroid/brain/brain_scipy_signal.py | 3 +- astroid/brain/brain_sqlalchemy.py | 3 +- astroid/brain/brain_ssl.py | 5 +-- astroid/brain/brain_subprocess.py | 3 +- astroid/brain/brain_threading.py | 3 +- astroid/brain/brain_type.py | 4 ++- astroid/brain/brain_typing.py | 5 +-- astroid/brain/brain_unittest.py | 3 +- pyproject.toml | 33 +++++++++++++++++++ 37 files changed, 114 insertions(+), 47 deletions(-) diff --git a/astroid/_ast.py b/astroid/_ast.py index 44800e3829..e3ad97db77 100644 --- a/astroid/_ast.py +++ b/astroid/_ast.py @@ -32,7 +32,7 @@ def parse( def parse_function_type_comment(type_comment: str) -> FunctionType | None: """Given a correct type comment, obtain a FunctionType object.""" - func_type = ast.parse(type_comment, "", "func_type") # type: ignore[attr-defined] + func_type = ast.parse(type_comment, "", "func_type") return FunctionType(argtypes=func_type.argtypes, returns=func_type.returns) diff --git a/astroid/brain/brain_argparse.py b/astroid/brain/brain_argparse.py index d0da4080a3..500b8d74cd 100644 --- a/astroid/brain/brain_argparse.py +++ b/astroid/brain/brain_argparse.py @@ -4,9 +4,10 @@ from __future__ import annotations -from astroid import arguments, inference_tip, nodes +from astroid import arguments, nodes from astroid.context import InferenceContext from astroid.exceptions import UseInferenceDefault +from astroid.inference_tip import inference_tip from astroid.manager import AstroidManager diff --git a/astroid/brain/brain_boto3.py b/astroid/brain/brain_boto3.py index 55bca14fc8..3a95feb816 100644 --- a/astroid/brain/brain_boto3.py +++ b/astroid/brain/brain_boto3.py @@ -4,14 +4,14 @@ """Astroid hooks for understanding ``boto3.ServiceRequest()``.""" -from astroid import extract_node +from astroid.builder import extract_node from astroid.manager import AstroidManager from astroid.nodes.scoped_nodes import ClassDef BOTO_SERVICE_FACTORY_QUALIFIED_NAME = "boto3.resources.base.ServiceResource" -def service_request_transform(node): +def service_request_transform(node: ClassDef) -> ClassDef: """Transform ServiceResource to look like dynamic classes.""" code = """ def __getattr__(self, attr): @@ -22,7 +22,7 @@ def __getattr__(self, attr): return node -def _looks_like_boto3_service_request(node) -> bool: +def _looks_like_boto3_service_request(node: ClassDef) -> bool: return node.qname() == BOTO_SERVICE_FACTORY_QUALIFIED_NAME diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py index 4f86c613fa..64ab8ef689 100644 --- a/astroid/brain/brain_builtin_inference.py +++ b/astroid/brain/brain_builtin_inference.py @@ -11,7 +11,7 @@ from functools import partial from typing import TYPE_CHECKING, Any, NoReturn, Union, cast -from astroid import arguments, helpers, inference_tip, nodes, objects, util +from astroid import arguments, helpers, nodes, objects, util from astroid.builder import AstroidBuilder from astroid.context import InferenceContext from astroid.exceptions import ( @@ -21,6 +21,7 @@ MroError, UseInferenceDefault, ) +from astroid.inference_tip import inference_tip from astroid.manager import AstroidManager from astroid.nodes import scoped_nodes from astroid.typing import ( @@ -844,7 +845,7 @@ def _class_or_tuple_to_container( return class_container -def infer_len(node, context: InferenceContext | None = None): +def infer_len(node, context: InferenceContext | None = None) -> nodes.Const: """Infer length calls. :param nodes.Call node: len call to infer @@ -867,7 +868,7 @@ def infer_len(node, context: InferenceContext | None = None): raise UseInferenceDefault(str(exc)) from exc -def infer_str(node, context: InferenceContext | None = None): +def infer_str(node, context: InferenceContext | None = None) -> nodes.Const: """Infer str() calls. :param nodes.Call node: str() call to infer @@ -926,7 +927,7 @@ def infer_dict_fromkeys(node, context: InferenceContext | None = None): will be inferred instead. """ - def _build_dict_with_elements(elements): + def _build_dict_with_elements(elements: list) -> nodes.Dict: new_node = nodes.Dict( col_offset=node.col_offset, lineno=node.lineno, diff --git a/astroid/brain/brain_crypt.py b/astroid/brain/brain_crypt.py index 2a6abbd7ca..71f9dfcb34 100644 --- a/astroid/brain/brain_crypt.py +++ b/astroid/brain/brain_crypt.py @@ -2,12 +2,13 @@ # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def _re_transform(): +def _re_transform() -> nodes.Module: return parse( """ from collections import namedtuple diff --git a/astroid/brain/brain_ctypes.py b/astroid/brain/brain_ctypes.py index 863ea1874a..8ae10bc952 100644 --- a/astroid/brain/brain_ctypes.py +++ b/astroid/brain/brain_ctypes.py @@ -12,12 +12,13 @@ """ import sys +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def enrich_ctypes_redefined_types(): +def enrich_ctypes_redefined_types() -> nodes.Module: """ For each ctypes redefined types, overload 'value' and '_type_' members definition. diff --git a/astroid/brain/brain_curses.py b/astroid/brain/brain_curses.py index f06c52f979..5824fd7f35 100644 --- a/astroid/brain/brain_curses.py +++ b/astroid/brain/brain_curses.py @@ -2,12 +2,13 @@ # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def _curses_transform(): +def _curses_transform() -> nodes.Module: return parse( """ A_ALTCHARSET = 1 diff --git a/astroid/brain/brain_datetime.py b/astroid/brain/brain_datetime.py index 06b011ce49..f4cb6670bd 100644 --- a/astroid/brain/brain_datetime.py +++ b/astroid/brain/brain_datetime.py @@ -2,13 +2,14 @@ # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import AstroidBuilder from astroid.const import PY312_PLUS from astroid.manager import AstroidManager -def datetime_transform(): +def datetime_transform() -> nodes.Module: """The datetime module was C-accelerated in Python 3.12, so use the Python source.""" return AstroidBuilder(AstroidManager()).string_build("from _pydatetime import *") diff --git a/astroid/brain/brain_dateutil.py b/astroid/brain/brain_dateutil.py index 3630639b0a..c27343f961 100644 --- a/astroid/brain/brain_dateutil.py +++ b/astroid/brain/brain_dateutil.py @@ -6,12 +6,13 @@ import textwrap +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import AstroidBuilder from astroid.manager import AstroidManager -def dateutil_transform(): +def dateutil_transform() -> nodes.Module: return AstroidBuilder(AstroidManager()).string_build( textwrap.dedent( """ diff --git a/astroid/brain/brain_functools.py b/astroid/brain/brain_functools.py index 2adf2b604f..c11b856ecc 100644 --- a/astroid/brain/brain_functools.py +++ b/astroid/brain/brain_functools.py @@ -10,7 +10,8 @@ from functools import partial from itertools import chain -from astroid import BoundMethod, arguments, extract_node, nodes, objects +from astroid import BoundMethod, arguments, nodes, objects +from astroid.builder import extract_node from astroid.context import InferenceContext from astroid.exceptions import InferenceError, UseInferenceDefault from astroid.inference_tip import inference_tip diff --git a/astroid/brain/brain_hashlib.py b/astroid/brain/brain_hashlib.py index 91aa4c4277..a17645a8dd 100644 --- a/astroid/brain/brain_hashlib.py +++ b/astroid/brain/brain_hashlib.py @@ -2,12 +2,13 @@ # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def _hashlib_transform(): +def _hashlib_transform() -> nodes.Module: init_signature = "value='', usedforsecurity=True" digest_signature = "self" shake_digest_signature = "self, length" diff --git a/astroid/brain/brain_http.py b/astroid/brain/brain_http.py index f34f381df8..3a8a8588af 100644 --- a/astroid/brain/brain_http.py +++ b/astroid/brain/brain_http.py @@ -5,12 +5,13 @@ """Astroid brain hints for some of the `http` module.""" import textwrap +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import AstroidBuilder from astroid.manager import AstroidManager -def _http_transform(): +def _http_transform() -> nodes.Module: code = textwrap.dedent( """ from enum import IntEnum @@ -140,7 +141,7 @@ def description(self): return AstroidBuilder(AstroidManager()).string_build(code) -def _http_client_transform(): +def _http_client_transform() -> nodes.Module: return AstroidBuilder(AstroidManager()).string_build( textwrap.dedent( """ diff --git a/astroid/brain/brain_hypothesis.py b/astroid/brain/brain_hypothesis.py index 6180520f30..ba20f0683c 100644 --- a/astroid/brain/brain_hypothesis.py +++ b/astroid/brain/brain_hypothesis.py @@ -27,7 +27,7 @@ def a_strategy(draw): ) -def is_decorated_with_st_composite(node) -> bool: +def is_decorated_with_st_composite(node: FunctionDef) -> bool: """Return whether a decorated node has @st.composite applied.""" if node.decorators and node.args.args and node.args.args[0].name == "draw": for decorator_attribute in node.decorators.nodes: @@ -36,11 +36,12 @@ def is_decorated_with_st_composite(node) -> bool: return False -def remove_draw_parameter_from_composite_strategy(node): +def remove_draw_parameter_from_composite_strategy(node: FunctionDef) -> FunctionDef: """Given that the FunctionDef is decorated with @st.composite, remove the first argument (`draw`) - it's always supplied by Hypothesis so we don't need to emit the no-value-for-parameter lint. """ + assert isinstance(node.args.args, list) del node.args.args[0] del node.args.annotations[0] del node.args.type_comment_args[0] diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py index 71091d8872..72a07c1187 100644 --- a/astroid/brain/brain_namedtuple_enum.py +++ b/astroid/brain/brain_namedtuple_enum.py @@ -13,7 +13,7 @@ from typing import Final import astroid -from astroid import arguments, bases, inference_tip, nodes, util +from astroid import arguments, bases, nodes, util from astroid.builder import AstroidBuilder, _extract_single_node, extract_node from astroid.context import InferenceContext from astroid.exceptions import ( @@ -22,6 +22,7 @@ InferenceError, UseInferenceDefault, ) +from astroid.inference_tip import inference_tip from astroid.manager import AstroidManager ENUM_QNAME: Final[str] = "enum.Enum" diff --git a/astroid/brain/brain_numpy_core_fromnumeric.py b/astroid/brain/brain_numpy_core_fromnumeric.py index c6be20b6ea..ce4173c110 100644 --- a/astroid/brain/brain_numpy_core_fromnumeric.py +++ b/astroid/brain/brain_numpy_core_fromnumeric.py @@ -3,12 +3,13 @@ # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt """Astroid hooks for numpy.core.fromnumeric module.""" +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def numpy_core_fromnumeric_transform(): +def numpy_core_fromnumeric_transform() -> nodes.Module: return parse( """ def sum(a, axis=None, dtype=None, out=None, keepdims=None, initial=None): diff --git a/astroid/brain/brain_numpy_core_multiarray.py b/astroid/brain/brain_numpy_core_multiarray.py index 404e21cf1b..16cdd6f918 100644 --- a/astroid/brain/brain_numpy_core_multiarray.py +++ b/astroid/brain/brain_numpy_core_multiarray.py @@ -6,6 +6,7 @@ import functools +from astroid import nodes from astroid.brain.brain_numpy_utils import ( attribute_looks_like_numpy_member, infer_numpy_member, @@ -18,7 +19,7 @@ from astroid.nodes.node_classes import Attribute, Name -def numpy_core_multiarray_transform(): +def numpy_core_multiarray_transform() -> nodes.Module: return parse( """ # different functions defined in multiarray.py diff --git a/astroid/brain/brain_numpy_core_numeric.py b/astroid/brain/brain_numpy_core_numeric.py index 7149c85daf..df4ae0cbb1 100644 --- a/astroid/brain/brain_numpy_core_numeric.py +++ b/astroid/brain/brain_numpy_core_numeric.py @@ -6,6 +6,7 @@ import functools +from astroid import nodes from astroid.brain.brain_numpy_utils import ( attribute_looks_like_numpy_member, infer_numpy_member, @@ -17,7 +18,7 @@ from astroid.nodes.node_classes import Attribute -def numpy_core_numeric_transform(): +def numpy_core_numeric_transform() -> nodes.Module: return parse( """ # different functions defined in numeric.py diff --git a/astroid/brain/brain_numpy_core_numerictypes.py b/astroid/brain/brain_numpy_core_numerictypes.py index 6de299d72e..7111c837a3 100644 --- a/astroid/brain/brain_numpy_core_numerictypes.py +++ b/astroid/brain/brain_numpy_core_numerictypes.py @@ -5,13 +5,14 @@ # TODO(hippo91) : correct the methods signature. """Astroid hooks for numpy.core.numerictypes module.""" +from astroid import nodes from astroid.brain.brain_numpy_utils import numpy_supports_type_hints from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def numpy_core_numerictypes_transform(): +def numpy_core_numerictypes_transform() -> nodes.Module: # TODO: Uniformize the generic API with the ndarray one. # According to numpy doc the generic object should expose # the same API than ndarray. This has been done here partially diff --git a/astroid/brain/brain_numpy_core_umath.py b/astroid/brain/brain_numpy_core_umath.py index 61f3354408..a048a1c06b 100644 --- a/astroid/brain/brain_numpy_core_umath.py +++ b/astroid/brain/brain_numpy_core_umath.py @@ -7,12 +7,13 @@ # typecheck in `_emit_no_member` function) """Astroid hooks for numpy.core.umath module.""" +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def numpy_core_umath_transform(): +def numpy_core_umath_transform() -> nodes.Module: ufunc_optional_keyword_arguments = ( """out=None, where=True, casting='same_kind', order='K', """ """dtype=None, subok=True""" diff --git a/astroid/brain/brain_numpy_ma.py b/astroid/brain/brain_numpy_ma.py index 743e462d20..e61acb5c15 100644 --- a/astroid/brain/brain_numpy_ma.py +++ b/astroid/brain/brain_numpy_ma.py @@ -4,12 +4,13 @@ """Astroid hooks for numpy ma module.""" +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def numpy_ma_transform(): +def numpy_ma_transform() -> nodes.Module: """ Infer the call of various numpy.ma functions. diff --git a/astroid/brain/brain_numpy_random_mtrand.py b/astroid/brain/brain_numpy_random_mtrand.py index 83b1ab06ad..be1c957861 100644 --- a/astroid/brain/brain_numpy_random_mtrand.py +++ b/astroid/brain/brain_numpy_random_mtrand.py @@ -4,12 +4,13 @@ # TODO(hippo91) : correct the functions return types """Astroid hooks for numpy.random.mtrand module.""" +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def numpy_random_mtrand_transform(): +def numpy_random_mtrand_transform() -> nodes.Module: return parse( """ def beta(a, b, size=None): return uninferable diff --git a/astroid/brain/brain_pathlib.py b/astroid/brain/brain_pathlib.py index d0f531324b..62daaafc1b 100644 --- a/astroid/brain/brain_pathlib.py +++ b/astroid/brain/brain_pathlib.py @@ -6,10 +6,11 @@ from collections.abc import Iterator -from astroid import bases, context, inference_tip, nodes +from astroid import bases, context, nodes from astroid.builder import _extract_single_node from astroid.const import PY313_PLUS from astroid.exceptions import InferenceError, UseInferenceDefault +from astroid.inference_tip import inference_tip from astroid.manager import AstroidManager PATH_TEMPLATE = """ diff --git a/astroid/brain/brain_pkg_resources.py b/astroid/brain/brain_pkg_resources.py index a844d15b31..e2bd669100 100644 --- a/astroid/brain/brain_pkg_resources.py +++ b/astroid/brain/brain_pkg_resources.py @@ -2,12 +2,13 @@ # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt -from astroid import parse +from astroid import nodes from astroid.brain.helpers import register_module_extender +from astroid.builder import parse from astroid.manager import AstroidManager -def pkg_resources_transform(): +def pkg_resources_transform() -> nodes.Module: return parse( """ def require(*requirements): diff --git a/astroid/brain/brain_pytest.py b/astroid/brain/brain_pytest.py index 0e0db39041..6d06267b3d 100644 --- a/astroid/brain/brain_pytest.py +++ b/astroid/brain/brain_pytest.py @@ -3,12 +3,13 @@ # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt """Astroid hooks for pytest.""" +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import AstroidBuilder from astroid.manager import AstroidManager -def pytest_transform(): +def pytest_transform() -> nodes.Module: return AstroidBuilder(AstroidManager()).string_build( """ diff --git a/astroid/brain/brain_qt.py b/astroid/brain/brain_qt.py index 4badfce840..30581e0ea5 100644 --- a/astroid/brain/brain_qt.py +++ b/astroid/brain/brain_qt.py @@ -4,9 +4,9 @@ """Astroid hooks for the PyQT library.""" -from astroid import nodes, parse +from astroid import nodes from astroid.brain.helpers import register_module_extender -from astroid.builder import AstroidBuilder +from astroid.builder import AstroidBuilder, parse from astroid.manager import AstroidManager diff --git a/astroid/brain/brain_re.py b/astroid/brain/brain_re.py index 19f2a5b39c..64646454b6 100644 --- a/astroid/brain/brain_re.py +++ b/astroid/brain/brain_re.py @@ -4,10 +4,11 @@ from __future__ import annotations -from astroid import context, inference_tip, nodes +from astroid import context, nodes from astroid.brain.helpers import register_module_extender from astroid.builder import _extract_single_node, parse from astroid.const import PY311_PLUS +from astroid.inference_tip import inference_tip from astroid.manager import AstroidManager diff --git a/astroid/brain/brain_regex.py b/astroid/brain/brain_regex.py index 5a2d81e809..70fb94610c 100644 --- a/astroid/brain/brain_regex.py +++ b/astroid/brain/brain_regex.py @@ -4,9 +4,10 @@ from __future__ import annotations -from astroid import context, inference_tip, nodes +from astroid import context, nodes from astroid.brain.helpers import register_module_extender from astroid.builder import _extract_single_node, parse +from astroid.inference_tip import inference_tip from astroid.manager import AstroidManager diff --git a/astroid/brain/brain_responses.py b/astroid/brain/brain_responses.py index 0a0de8b558..f2e606976b 100644 --- a/astroid/brain/brain_responses.py +++ b/astroid/brain/brain_responses.py @@ -10,12 +10,13 @@ See: https://github.com/getsentry/responses/blob/master/responses.py """ +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def responses_funcs(): +def responses_funcs() -> nodes.Module: return parse( """ DELETE = "DELETE" diff --git a/astroid/brain/brain_scipy_signal.py b/astroid/brain/brain_scipy_signal.py index 7d17a1e953..a7a257628a 100755 --- a/astroid/brain/brain_scipy_signal.py +++ b/astroid/brain/brain_scipy_signal.py @@ -3,12 +3,13 @@ # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt """Astroid hooks for scipy.signal module.""" +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def scipy_signal(): +def scipy_signal() -> nodes.Module: return parse( """ # different functions defined in scipy.signals diff --git a/astroid/brain/brain_sqlalchemy.py b/astroid/brain/brain_sqlalchemy.py index d37b505bf2..8410d9e12f 100644 --- a/astroid/brain/brain_sqlalchemy.py +++ b/astroid/brain/brain_sqlalchemy.py @@ -2,12 +2,13 @@ # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def _session_transform(): +def _session_transform() -> nodes.Module: return parse( """ from sqlalchemy.orm.session import Session diff --git a/astroid/brain/brain_ssl.py b/astroid/brain/brain_ssl.py index 23d7ee4f73..de932dee5b 100644 --- a/astroid/brain/brain_ssl.py +++ b/astroid/brain/brain_ssl.py @@ -4,8 +4,9 @@ """Astroid hooks for the ssl library.""" -from astroid import parse +from astroid import nodes from astroid.brain.helpers import register_module_extender +from astroid.builder import parse from astroid.const import PY310_PLUS, PY312_PLUS from astroid.manager import AstroidManager @@ -49,7 +50,7 @@ class Options(_IntFlag): return enum -def ssl_transform(): +def ssl_transform() -> nodes.Module: return parse( f""" # Import necessary for conversion of objects defined in C into enums diff --git a/astroid/brain/brain_subprocess.py b/astroid/brain/brain_subprocess.py index fbc088a680..96855c6a15 100644 --- a/astroid/brain/brain_subprocess.py +++ b/astroid/brain/brain_subprocess.py @@ -4,13 +4,14 @@ import textwrap +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.const import PY310_PLUS, PY311_PLUS from astroid.manager import AstroidManager -def _subprocess_transform(): +def _subprocess_transform() -> nodes.Module: communicate = (bytes("string", "ascii"), bytes("string", "ascii")) communicate_signature = "def communicate(self, input=None, timeout=None)" args = """\ diff --git a/astroid/brain/brain_threading.py b/astroid/brain/brain_threading.py index 6c6f29bf06..95af2db069 100644 --- a/astroid/brain/brain_threading.py +++ b/astroid/brain/brain_threading.py @@ -2,12 +2,13 @@ # For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def _thread_transform(): +def _thread_transform() -> nodes.Module: return parse( """ class lock(object): diff --git a/astroid/brain/brain_type.py b/astroid/brain/brain_type.py index 6fd0179cbe..2fb06be53e 100644 --- a/astroid/brain/brain_type.py +++ b/astroid/brain/brain_type.py @@ -22,9 +22,11 @@ from __future__ import annotations -from astroid import extract_node, inference_tip, nodes +from astroid import nodes +from astroid.builder import extract_node from astroid.context import InferenceContext from astroid.exceptions import UseInferenceDefault +from astroid.inference_tip import inference_tip from astroid.manager import AstroidManager diff --git a/astroid/brain/brain_typing.py b/astroid/brain/brain_typing.py index 62f154b4f5..239e63af24 100644 --- a/astroid/brain/brain_typing.py +++ b/astroid/brain/brain_typing.py @@ -12,9 +12,9 @@ from functools import partial from typing import Final -from astroid import context, extract_node, inference_tip +from astroid import context from astroid.brain.helpers import register_module_extender -from astroid.builder import AstroidBuilder, _extract_single_node +from astroid.builder import AstroidBuilder, _extract_single_node, extract_node from astroid.const import PY312_PLUS, PY313_PLUS from astroid.exceptions import ( AstroidSyntaxError, @@ -22,6 +22,7 @@ InferenceError, UseInferenceDefault, ) +from astroid.inference_tip import inference_tip from astroid.manager import AstroidManager from astroid.nodes.node_classes import ( Assign, diff --git a/astroid/brain/brain_unittest.py b/astroid/brain/brain_unittest.py index a94df0a68e..4103ce0600 100644 --- a/astroid/brain/brain_unittest.py +++ b/astroid/brain/brain_unittest.py @@ -3,12 +3,13 @@ # Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt """Astroid hooks for unittest module.""" +from astroid import nodes from astroid.brain.helpers import register_module_extender from astroid.builder import parse from astroid.manager import AstroidManager -def IsolatedAsyncioTestCaseImport(): +def IsolatedAsyncioTestCaseImport() -> nodes.Module: """ In the unittest package, the IsolatedAsyncioTestCase class is imported lazily. diff --git a/pyproject.toml b/pyproject.toml index 7c7e29683a..61f8c3912b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,7 +64,40 @@ filterwarnings = "error" [tool.mypy] python_version = "3.9" files = [ + "astroid/_ast.py", + "astroid/_backport_stdlib_names.py", + "astroid/astroid_manager.py", + "astroid/brain/brain_crypt.py", + "astroid/brain/brain_ctypes.py", + "astroid/brain/brain_curses.py", + "astroid/brain/brain_datetime.py", + "astroid/brain/brain_dateutil.py", + "astroid/brain/brain_hashlib.py", + "astroid/brain/brain_http.py", + "astroid/brain/brain_hypothesis.py", + "astroid/brain/brain_numpy_core_einsumfunc.py", + "astroid/brain/brain_numpy_core_fromnumeric.py", + "astroid/brain/brain_numpy_core_function_base.py", + "astroid/brain/brain_numpy_core_multiarray.py", + "astroid/brain/brain_numpy_core_numeric.py", + "astroid/brain/brain_numpy_core_numerictypes.py", + "astroid/brain/brain_numpy_core_umath.py", + "astroid/brain/brain_numpy_ma.py", + "astroid/brain/brain_numpy_random_mtrand.py", + "astroid/brain/brain_pkg_resources.py", + "astroid/brain/brain_pytest.py", + "astroid/brain/brain_responses.py", + "astroid/brain/brain_scipy_signal.py", + "astroid/brain/brain_sqlalchemy.py", + "astroid/brain/brain_ssl.py", + "astroid/brain/brain_subprocess.py", + "astroid/brain/brain_threading.py", + "astroid/brain/brain_unittest.py", + "astroid/brain/brain_uuid.py", + "astroid/const.py", "astroid/interpreter/_import/", + "astroid/nodes/const.py", + "astroid/nodes/utils.py", ] always_false = [ "PY310_PLUS",