Skip to content

Commit 0871a4d

Browse files
authored
Update additional astroid imports (#10594)
1 parent 19e0f3e commit 0871a4d

File tree

16 files changed

+60
-53
lines changed

16 files changed

+60
-53
lines changed

pylint/checkers/async_checker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from typing import TYPE_CHECKING
1111

1212
import astroid
13+
import astroid.bases
14+
import astroid.exceptions
1315
from astroid import nodes
1416

1517
from pylint import checkers

pylint/checkers/base/basic_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from typing import TYPE_CHECKING, Literal, cast
1313

1414
import astroid
15-
from astroid import nodes, objects, util
15+
from astroid import bases, nodes, objects, util
1616

1717
from pylint import utils as lint_utils
1818
from pylint.checkers import BaseChecker, utils
@@ -311,7 +311,7 @@ def _check_using_constant_test(
311311
nodes.Lambda,
312312
nodes.FunctionDef,
313313
nodes.ClassDef,
314-
astroid.bases.Generator,
314+
bases.Generator,
315315
astroid.UnboundMethod,
316316
astroid.BoundMethod,
317317
nodes.Module,

pylint/checkers/base/name_checker/checker.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
from typing import TYPE_CHECKING
1818

1919
import astroid
20-
import astroid.bases
21-
from astroid import nodes
20+
from astroid import bases, nodes, util
2221
from astroid.typing import InferenceResult
2322

2423
from pylint import constants, interfaces
@@ -489,7 +488,7 @@ def visit_assignname( # pylint: disable=too-many-branches,too-many-statements
489488
elif isinstance(inferred_assign_type, nodes.ClassDef):
490489
self._check_name("class", node.name, node)
491490

492-
elif inferred_assign_type in (None, astroid.util.Uninferable):
491+
elif inferred_assign_type in (None, util.Uninferable):
493492
return
494493

495494
# Don't emit if the name redefines an import in an ImportError except handler
@@ -513,7 +512,7 @@ def visit_assignname( # pylint: disable=too-many-branches,too-many-statements
513512
node_type = "variable"
514513
if (
515514
(iattrs := tuple(node.frame().igetattr(node.name)))
516-
and astroid.util.Uninferable not in iattrs
515+
and util.Uninferable not in iattrs
517516
and len(iattrs) == 2
518517
and astroid.are_exclusive(*iattrs)
519518
):
@@ -663,7 +662,7 @@ def _assigns_typevar(node: nodes.NodeNG | None) -> str | None:
663662
def _assigns_typealias(node: nodes.NodeNG | None) -> bool:
664663
"""Check if a node is assigning a TypeAlias."""
665664
inferred = utils.safe_infer(node)
666-
if isinstance(inferred, (nodes.ClassDef, astroid.bases.UnionType)):
665+
if isinstance(inferred, (nodes.ClassDef, bases.UnionType)):
667666
qname = inferred.qname()
668667
if qname == "typing.TypeAlias":
669668
return True

pylint/checkers/classes/class_checker.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
from typing import TYPE_CHECKING, Any, NamedTuple, TypeAlias
1515

1616
import astroid
17-
import astroid.objects
18-
from astroid import bases, nodes, util
19-
from astroid.nodes import LocalsDictNodeNG
17+
import astroid.exceptions
18+
from astroid import bases, nodes, objects, util
2019
from astroid.typing import SuccessfulInferenceResult
2120

2221
from pylint.checkers import BaseChecker, utils
@@ -177,7 +176,7 @@ def _is_trivial_super_delegation(function: nodes.FunctionDef) -> bool:
177176

178177
# Anything other than a super call is non-trivial.
179178
super_call = safe_infer(expr)
180-
if not isinstance(super_call, astroid.objects.Super):
179+
if not isinstance(super_call, objects.Super):
181180
return False
182181

183182
# The name should be the same.
@@ -415,7 +414,7 @@ def _has_data_descriptor(cls: nodes.ClassDef, attr: str) -> bool:
415414

416415

417416
def _called_in_methods(
418-
func: LocalsDictNodeNG,
417+
func: nodes.LocalsDictNodeNG,
419418
klass: nodes.ClassDef,
420419
methods: Sequence[str],
421420
) -> bool:
@@ -1981,7 +1980,7 @@ def _is_type_self_call(self, expr: nodes.NodeNG) -> bool:
19811980
return False
19821981

19831982
@staticmethod
1984-
def _is_classmethod(func: LocalsDictNodeNG) -> bool:
1983+
def _is_classmethod(func: nodes.LocalsDictNodeNG) -> bool:
19851984
"""Check if the given *func* node is a class method."""
19861985
return isinstance(func, nodes.FunctionDef) and (
19871986
func.type == "classmethod" or func.name == "__class_getitem__"
@@ -2238,7 +2237,7 @@ def _check_init(self, node: nodes.FunctionDef, klass_node: nodes.ClassDef) -> No
22382237
_proxied=nodes.ClassDef(name="super") as p
22392238
) if is_builtin_object(p):
22402239
return
2241-
case astroid.objects.Super():
2240+
case objects.Super():
22422241
return
22432242
try:
22442243
method = not_called_yet.pop(klass)

pylint/checkers/imports.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from typing import TYPE_CHECKING, Any
1717

1818
import astroid
19+
import astroid.modutils
1920
from astroid import nodes
2021
from astroid.nodes._base_nodes import ImportNode
2122

@@ -1081,7 +1082,7 @@ def _check_preferred_module(self, node: ImportNode, mod_path: str) -> None:
10811082
"""Check if the module has a preferred replacement."""
10821083
mod_compare = [mod_path]
10831084
# build a comparison list of possible names using importfrom
1084-
if isinstance(node, astroid.nodes.node_classes.ImportFrom):
1085+
if isinstance(node, nodes.ImportFrom):
10851086
mod_compare = [f"{node.modname}.{name[0]}" for name in node.names]
10861087

10871088
# find whether there are matches with the import vs preferred_modules keys

pylint/checkers/nested_min_max.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
objects.DictValues,
2424
objects.DictKeys,
2525
objects.DictItems,
26-
nodes.node_classes.Dict,
26+
nodes.Dict,
2727
)
2828

2929

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
from typing import TYPE_CHECKING, Any, NamedTuple, TypeAlias, cast
1515

1616
import astroid
17-
import astroid.objects
18-
from astroid import bases, nodes
17+
from astroid import bases, nodes, objects
1918
from astroid.util import UninferableBase
2019

2120
from pylint import checkers
@@ -1858,7 +1857,7 @@ def _check_unnecessary_comprehension(self, node: nodes.Comprehension) -> None:
18581857
args: tuple[str] | None = None
18591858
inferred = utils.safe_infer(node.iter)
18601859
match (node.parent, inferred):
1861-
case [nodes.DictComp(), astroid.objects.DictItems()]:
1860+
case [nodes.DictComp(), objects.DictItems()]:
18621861
args = (f"dict({node.iter.func.expr.as_string()})",)
18631862
case [nodes.ListComp(), nodes.List()]:
18641863
args = (f"list({node.iter.as_string()})",)

pylint/checkers/strings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from typing import TYPE_CHECKING, Literal
1616

1717
import astroid
18-
from astroid import bases, nodes, util
18+
from astroid import arguments, bases, nodes, util
1919
from astroid.typing import SuccessfulInferenceResult
2020

2121
from pylint.checkers import BaseChecker, BaseRawFileChecker, BaseTokenChecker, utils
@@ -473,7 +473,7 @@ def _check_new_format(self, node: nodes.Call, func: bases.BoundMethod) -> None:
473473
if not (isinstance(strnode, nodes.Const) and isinstance(strnode.value, str)):
474474
return
475475
try:
476-
call_site = astroid.arguments.CallSite.from_call(node)
476+
call_site = arguments.CallSite.from_call(node)
477477
except astroid.InferenceError:
478478
return
479479

pylint/checkers/typecheck.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
from typing import TYPE_CHECKING, Any, Literal, TypeAlias
1919

2020
import astroid
21+
import astroid.context
2122
import astroid.exceptions
2223
import astroid.helpers
23-
from astroid import arguments, bases, nodes, util
24+
import astroid.interpreter
25+
import astroid.modutils
26+
from astroid import arguments, bases, nodes, objects, util
2427
from astroid.nodes import _base_nodes
2528
from astroid.typing import InferenceResult, SuccessfulInferenceResult
2629

@@ -476,7 +479,7 @@ def _emit_no_member(
476479
# at some point during the runtime of the program.
477480
if utils.is_attribute_typed_annotation(owner, node.attrname):
478481
return False
479-
if isinstance(owner, astroid.objects.Super):
482+
if isinstance(owner, objects.Super):
480483
# Verify if we are dealing with an invalid Super object.
481484
# If it is invalid, then there's no point in checking that
482485
# it has the required attribute. Also, don't fail if the
@@ -605,9 +608,9 @@ def _determine_callable(
605608
callable_obj: nodes.NodeNG,
606609
) -> tuple[CallableObjects, int, str]:
607610
# TODO: The typing of the second return variable is actually Literal[0,1]
608-
# We need typing on astroid.NodeNG.implicit_parameters for this
611+
# We need typing on nodes.NodeNG.implicit_parameters for this
609612
# TODO: The typing of the third return variable can be narrowed to a Literal
610-
# We need typing on astroid.NodeNG.type for this
613+
# We need typing on nodes.NodeNG.type for this
611614

612615
# Ordering is important, since BoundMethod is a subclass of UnboundMethod,
613616
# and Function inherits Lambda.
@@ -1478,7 +1481,7 @@ def visit_call(self, node: nodes.Call) -> None:
14781481

14791482
# Build the set of keyword arguments, checking for duplicate keywords,
14801483
# and count the positional arguments.
1481-
call_site = astroid.arguments.CallSite.from_call(node)
1484+
call_site = arguments.CallSite.from_call(node)
14821485

14831486
# Warn about duplicated keyword arguments, such as `f=24, **{'f': 24}`
14841487
for keyword in call_site.duplicated_keywords:
@@ -1853,7 +1856,7 @@ def _check_invalid_slice_index(self, node: nodes.Slice) -> None:
18531856
nodes.List,
18541857
nodes.Dict,
18551858
nodes.Tuple,
1856-
astroid.objects.FrozenSet,
1859+
objects.FrozenSet,
18571860
nodes.Set,
18581861
)
18591862
if not (
@@ -1883,15 +1886,15 @@ def visit_with(self, node: nodes.With) -> None:
18831886
match inferred := safe_infer(ctx_mgr, context=context):
18841887
case _ if not inferred:
18851888
continue
1886-
case astroid.bases.Generator():
1889+
case bases.Generator():
18871890
# Check if we are dealing with a function decorated
18881891
# with contextlib.contextmanager.
18891892
if decorated_with(
18901893
inferred.parent, self.linter.config.contextmanager_decorators
18911894
):
18921895
continue
18931896
# Check if it's an AsyncGenerator decorated with asynccontextmanager
1894-
if isinstance(inferred, astroid.bases.AsyncGenerator):
1897+
if isinstance(inferred, bases.AsyncGenerator):
18951898
async_decorators = ["contextlib.asynccontextmanager"]
18961899
if decorated_with(inferred.parent, async_decorators):
18971900
self.add_message(

pylint/checkers/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
from re import Match
1919
from typing import TYPE_CHECKING, TypeVar
2020

21-
import astroid.objects
22-
from astroid import TooManyLevelsError, nodes, util
21+
import astroid
22+
import astroid.exceptions
23+
import astroid.helpers
24+
from astroid import TooManyLevelsError, bases, nodes, objects, util
2325
from astroid.context import InferenceContext
2426
from astroid.exceptions import AstroidError
2527
from astroid.nodes._base_nodes import ImportNode, Statement
@@ -852,7 +854,7 @@ def _is_property_decorator(decorator: nodes.Name) -> bool:
852854
inferred = safe_infer(returns[0].value)
853855
if (
854856
inferred
855-
and isinstance(inferred, astroid.objects.Property)
857+
and isinstance(inferred, objects.Property)
856858
and isinstance(inferred.function, nodes.FunctionDef)
857859
):
858860
return decorated_with_property(inferred.function)
@@ -1006,7 +1008,7 @@ def find_except_wrapper_node_in_scope(
10061008
"""Return the ExceptHandler in which the node is, without going out of scope."""
10071009
for current in node.node_ancestors():
10081010
match current:
1009-
case astroid.scoped_nodes.LocalsDictNodeNG():
1011+
case nodes.LocalsDictNodeNG():
10101012
# If we're inside a function/class definition, we don't want to keep checking
10111013
# higher ancestors for `except` clauses, because if these exist, it means our
10121014
# function/class was defined in an `except` clause, rather than the current code
@@ -1287,9 +1289,7 @@ def _supports_protocol(
12871289
case nodes.ComprehensionScope():
12881290
return True
12891291

1290-
case astroid.bases.Proxy(
1291-
_proxied=astroid.BaseInstance() as p
1292-
) if has_known_bases(p):
1292+
case bases.Proxy(_proxied=astroid.BaseInstance() as p) if has_known_bases(p):
12931293
return protocol_callback(p)
12941294

12951295
return False

0 commit comments

Comments
 (0)