Skip to content

Commit 887668b

Browse files
authored
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
1 parent ba331c0 commit 887668b

37 files changed

+114
-47
lines changed

astroid/_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def parse(
3232

3333
def parse_function_type_comment(type_comment: str) -> FunctionType | None:
3434
"""Given a correct type comment, obtain a FunctionType object."""
35-
func_type = ast.parse(type_comment, "<type_comment>", "func_type") # type: ignore[attr-defined]
35+
func_type = ast.parse(type_comment, "<type_comment>", "func_type")
3636
return FunctionType(argtypes=func_type.argtypes, returns=func_type.returns)
3737

3838

astroid/brain/brain_argparse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
from __future__ import annotations
66

7-
from astroid import arguments, inference_tip, nodes
7+
from astroid import arguments, nodes
88
from astroid.context import InferenceContext
99
from astroid.exceptions import UseInferenceDefault
10+
from astroid.inference_tip import inference_tip
1011
from astroid.manager import AstroidManager
1112

1213

astroid/brain/brain_boto3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
"""Astroid hooks for understanding ``boto3.ServiceRequest()``."""
66

7-
from astroid import extract_node
7+
from astroid.builder import extract_node
88
from astroid.manager import AstroidManager
99
from astroid.nodes.scoped_nodes import ClassDef
1010

1111
BOTO_SERVICE_FACTORY_QUALIFIED_NAME = "boto3.resources.base.ServiceResource"
1212

1313

14-
def service_request_transform(node):
14+
def service_request_transform(node: ClassDef) -> ClassDef:
1515
"""Transform ServiceResource to look like dynamic classes."""
1616
code = """
1717
def __getattr__(self, attr):
@@ -22,7 +22,7 @@ def __getattr__(self, attr):
2222
return node
2323

2424

25-
def _looks_like_boto3_service_request(node) -> bool:
25+
def _looks_like_boto3_service_request(node: ClassDef) -> bool:
2626
return node.qname() == BOTO_SERVICE_FACTORY_QUALIFIED_NAME
2727

2828

astroid/brain/brain_builtin_inference.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from functools import partial
1212
from typing import TYPE_CHECKING, Any, NoReturn, Union, cast
1313

14-
from astroid import arguments, helpers, inference_tip, nodes, objects, util
14+
from astroid import arguments, helpers, nodes, objects, util
1515
from astroid.builder import AstroidBuilder
1616
from astroid.context import InferenceContext
1717
from astroid.exceptions import (
@@ -21,6 +21,7 @@
2121
MroError,
2222
UseInferenceDefault,
2323
)
24+
from astroid.inference_tip import inference_tip
2425
from astroid.manager import AstroidManager
2526
from astroid.nodes import scoped_nodes
2627
from astroid.typing import (
@@ -844,7 +845,7 @@ def _class_or_tuple_to_container(
844845
return class_container
845846

846847

847-
def infer_len(node, context: InferenceContext | None = None):
848+
def infer_len(node, context: InferenceContext | None = None) -> nodes.Const:
848849
"""Infer length calls.
849850
850851
:param nodes.Call node: len call to infer
@@ -867,7 +868,7 @@ def infer_len(node, context: InferenceContext | None = None):
867868
raise UseInferenceDefault(str(exc)) from exc
868869

869870

870-
def infer_str(node, context: InferenceContext | None = None):
871+
def infer_str(node, context: InferenceContext | None = None) -> nodes.Const:
871872
"""Infer str() calls.
872873
873874
:param nodes.Call node: str() call to infer
@@ -926,7 +927,7 @@ def infer_dict_fromkeys(node, context: InferenceContext | None = None):
926927
will be inferred instead.
927928
"""
928929

929-
def _build_dict_with_elements(elements):
930+
def _build_dict_with_elements(elements: list) -> nodes.Dict:
930931
new_node = nodes.Dict(
931932
col_offset=node.col_offset,
932933
lineno=node.lineno,

astroid/brain/brain_crypt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
33
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
44

5+
from astroid import nodes
56
from astroid.brain.helpers import register_module_extender
67
from astroid.builder import parse
78
from astroid.manager import AstroidManager
89

910

10-
def _re_transform():
11+
def _re_transform() -> nodes.Module:
1112
return parse(
1213
"""
1314
from collections import namedtuple

astroid/brain/brain_ctypes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
"""
1313
import sys
1414

15+
from astroid import nodes
1516
from astroid.brain.helpers import register_module_extender
1617
from astroid.builder import parse
1718
from astroid.manager import AstroidManager
1819

1920

20-
def enrich_ctypes_redefined_types():
21+
def enrich_ctypes_redefined_types() -> nodes.Module:
2122
"""
2223
For each ctypes redefined types, overload 'value' and '_type_' members
2324
definition.

astroid/brain/brain_curses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
33
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
44

5+
from astroid import nodes
56
from astroid.brain.helpers import register_module_extender
67
from astroid.builder import parse
78
from astroid.manager import AstroidManager
89

910

10-
def _curses_transform():
11+
def _curses_transform() -> nodes.Module:
1112
return parse(
1213
"""
1314
A_ALTCHARSET = 1

astroid/brain/brain_datetime.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
33
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
44

5+
from astroid import nodes
56
from astroid.brain.helpers import register_module_extender
67
from astroid.builder import AstroidBuilder
78
from astroid.const import PY312_PLUS
89
from astroid.manager import AstroidManager
910

1011

11-
def datetime_transform():
12+
def datetime_transform() -> nodes.Module:
1213
"""The datetime module was C-accelerated in Python 3.12, so use the
1314
Python source."""
1415
return AstroidBuilder(AstroidManager()).string_build("from _pydatetime import *")

astroid/brain/brain_dateutil.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
import textwrap
88

9+
from astroid import nodes
910
from astroid.brain.helpers import register_module_extender
1011
from astroid.builder import AstroidBuilder
1112
from astroid.manager import AstroidManager
1213

1314

14-
def dateutil_transform():
15+
def dateutil_transform() -> nodes.Module:
1516
return AstroidBuilder(AstroidManager()).string_build(
1617
textwrap.dedent(
1718
"""

astroid/brain/brain_functools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from functools import partial
1111
from itertools import chain
1212

13-
from astroid import BoundMethod, arguments, extract_node, nodes, objects
13+
from astroid import BoundMethod, arguments, nodes, objects
14+
from astroid.builder import extract_node
1415
from astroid.context import InferenceContext
1516
from astroid.exceptions import InferenceError, UseInferenceDefault
1617
from astroid.inference_tip import inference_tip

astroid/brain/brain_hashlib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
33
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
44

5+
from astroid import nodes
56
from astroid.brain.helpers import register_module_extender
67
from astroid.builder import parse
78
from astroid.manager import AstroidManager
89

910

10-
def _hashlib_transform():
11+
def _hashlib_transform() -> nodes.Module:
1112
init_signature = "value='', usedforsecurity=True"
1213
digest_signature = "self"
1314
shake_digest_signature = "self, length"

astroid/brain/brain_http.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
"""Astroid brain hints for some of the `http` module."""
66
import textwrap
77

8+
from astroid import nodes
89
from astroid.brain.helpers import register_module_extender
910
from astroid.builder import AstroidBuilder
1011
from astroid.manager import AstroidManager
1112

1213

13-
def _http_transform():
14+
def _http_transform() -> nodes.Module:
1415
code = textwrap.dedent(
1516
"""
1617
from enum import IntEnum
@@ -140,7 +141,7 @@ def description(self):
140141
return AstroidBuilder(AstroidManager()).string_build(code)
141142

142143

143-
def _http_client_transform():
144+
def _http_client_transform() -> nodes.Module:
144145
return AstroidBuilder(AstroidManager()).string_build(
145146
textwrap.dedent(
146147
"""

astroid/brain/brain_hypothesis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def a_strategy(draw):
2727
)
2828

2929

30-
def is_decorated_with_st_composite(node) -> bool:
30+
def is_decorated_with_st_composite(node: FunctionDef) -> bool:
3131
"""Return whether a decorated node has @st.composite applied."""
3232
if node.decorators and node.args.args and node.args.args[0].name == "draw":
3333
for decorator_attribute in node.decorators.nodes:
@@ -36,11 +36,12 @@ def is_decorated_with_st_composite(node) -> bool:
3636
return False
3737

3838

39-
def remove_draw_parameter_from_composite_strategy(node):
39+
def remove_draw_parameter_from_composite_strategy(node: FunctionDef) -> FunctionDef:
4040
"""Given that the FunctionDef is decorated with @st.composite, remove the
4141
first argument (`draw`) - it's always supplied by Hypothesis so we don't
4242
need to emit the no-value-for-parameter lint.
4343
"""
44+
assert isinstance(node.args.args, list)
4445
del node.args.args[0]
4546
del node.args.annotations[0]
4647
del node.args.type_comment_args[0]

astroid/brain/brain_namedtuple_enum.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from typing import Final
1414

1515
import astroid
16-
from astroid import arguments, bases, inference_tip, nodes, util
16+
from astroid import arguments, bases, nodes, util
1717
from astroid.builder import AstroidBuilder, _extract_single_node, extract_node
1818
from astroid.context import InferenceContext
1919
from astroid.exceptions import (
@@ -22,6 +22,7 @@
2222
InferenceError,
2323
UseInferenceDefault,
2424
)
25+
from astroid.inference_tip import inference_tip
2526
from astroid.manager import AstroidManager
2627

2728
ENUM_QNAME: Final[str] = "enum.Enum"

astroid/brain/brain_numpy_core_fromnumeric.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
44

55
"""Astroid hooks for numpy.core.fromnumeric module."""
6+
from astroid import nodes
67
from astroid.brain.helpers import register_module_extender
78
from astroid.builder import parse
89
from astroid.manager import AstroidManager
910

1011

11-
def numpy_core_fromnumeric_transform():
12+
def numpy_core_fromnumeric_transform() -> nodes.Module:
1213
return parse(
1314
"""
1415
def sum(a, axis=None, dtype=None, out=None, keepdims=None, initial=None):

astroid/brain/brain_numpy_core_multiarray.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import functools
88

9+
from astroid import nodes
910
from astroid.brain.brain_numpy_utils import (
1011
attribute_looks_like_numpy_member,
1112
infer_numpy_member,
@@ -18,7 +19,7 @@
1819
from astroid.nodes.node_classes import Attribute, Name
1920

2021

21-
def numpy_core_multiarray_transform():
22+
def numpy_core_multiarray_transform() -> nodes.Module:
2223
return parse(
2324
"""
2425
# different functions defined in multiarray.py

astroid/brain/brain_numpy_core_numeric.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import functools
88

9+
from astroid import nodes
910
from astroid.brain.brain_numpy_utils import (
1011
attribute_looks_like_numpy_member,
1112
infer_numpy_member,
@@ -17,7 +18,7 @@
1718
from astroid.nodes.node_classes import Attribute
1819

1920

20-
def numpy_core_numeric_transform():
21+
def numpy_core_numeric_transform() -> nodes.Module:
2122
return parse(
2223
"""
2324
# different functions defined in numeric.py

astroid/brain/brain_numpy_core_numerictypes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
# TODO(hippo91) : correct the methods signature.
66

77
"""Astroid hooks for numpy.core.numerictypes module."""
8+
from astroid import nodes
89
from astroid.brain.brain_numpy_utils import numpy_supports_type_hints
910
from astroid.brain.helpers import register_module_extender
1011
from astroid.builder import parse
1112
from astroid.manager import AstroidManager
1213

1314

14-
def numpy_core_numerictypes_transform():
15+
def numpy_core_numerictypes_transform() -> nodes.Module:
1516
# TODO: Uniformize the generic API with the ndarray one.
1617
# According to numpy doc the generic object should expose
1718
# the same API than ndarray. This has been done here partially

astroid/brain/brain_numpy_core_umath.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
# typecheck in `_emit_no_member` function)
88

99
"""Astroid hooks for numpy.core.umath module."""
10+
from astroid import nodes
1011
from astroid.brain.helpers import register_module_extender
1112
from astroid.builder import parse
1213
from astroid.manager import AstroidManager
1314

1415

15-
def numpy_core_umath_transform():
16+
def numpy_core_umath_transform() -> nodes.Module:
1617
ufunc_optional_keyword_arguments = (
1718
"""out=None, where=True, casting='same_kind', order='K', """
1819
"""dtype=None, subok=True"""

astroid/brain/brain_numpy_ma.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
"""Astroid hooks for numpy ma module."""
66

7+
from astroid import nodes
78
from astroid.brain.helpers import register_module_extender
89
from astroid.builder import parse
910
from astroid.manager import AstroidManager
1011

1112

12-
def numpy_ma_transform():
13+
def numpy_ma_transform() -> nodes.Module:
1314
"""
1415
Infer the call of various numpy.ma functions.
1516

astroid/brain/brain_numpy_random_mtrand.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
# TODO(hippo91) : correct the functions return types
66
"""Astroid hooks for numpy.random.mtrand module."""
7+
from astroid import nodes
78
from astroid.brain.helpers import register_module_extender
89
from astroid.builder import parse
910
from astroid.manager import AstroidManager
1011

1112

12-
def numpy_random_mtrand_transform():
13+
def numpy_random_mtrand_transform() -> nodes.Module:
1314
return parse(
1415
"""
1516
def beta(a, b, size=None): return uninferable

astroid/brain/brain_pathlib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
from collections.abc import Iterator
88

9-
from astroid import bases, context, inference_tip, nodes
9+
from astroid import bases, context, nodes
1010
from astroid.builder import _extract_single_node
1111
from astroid.const import PY313_PLUS
1212
from astroid.exceptions import InferenceError, UseInferenceDefault
13+
from astroid.inference_tip import inference_tip
1314
from astroid.manager import AstroidManager
1415

1516
PATH_TEMPLATE = """

astroid/brain/brain_pkg_resources.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE
33
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt
44

5-
from astroid import parse
5+
from astroid import nodes
66
from astroid.brain.helpers import register_module_extender
7+
from astroid.builder import parse
78
from astroid.manager import AstroidManager
89

910

10-
def pkg_resources_transform():
11+
def pkg_resources_transform() -> nodes.Module:
1112
return parse(
1213
"""
1314
def require(*requirements):

0 commit comments

Comments
 (0)