Method: pylint.checkers.imports.ImportsChecker._check_reimport
Calls: 1271, Exceptions: 0, Paths: 5Back
Path 1: 1088 calls (0.86)
ImportFrom (580) Import (508)
None (508) 'typing' (108) '__future__' (51) 'collections' (30) '' (28) 'enum' (20) 'dataclasses' (20) 'missing' (18) 'abc' (17) 'unknown' (12)
None (1023) 1 (56) 2 (5) 3 (3) 12 (1)
1def _check_reimport(
2 self,
3 node: ImportNode,
4 basename: str | None = None,
5 level: int | None = None,
6 ) -> None:
7 """Check if a module with the same name is already imported or aliased."""
8 if not self.linter.is_message_enabled(
9 "reimported"
10 ) and not self.linter.is_message_enabled("shadowed-import"):
11 return
12
13 frame = node.frame(future=True)
14 root = node.root()
15 contexts = [(frame, level)]
16 if root is not frame:
17 contexts.append((root, None))
18
19 for known_context, known_level in contexts:
20 for name, alias in node.names:
21 first, msg = _get_first_import(
22 node, known_context, name, basename, known_level, alias
23 )
24 if first is not None and msg is not None:
25 name = name if msg == "reimported" else alias
26 self.add_message(
27 msg, node=node, args=(name, first.fromlineno), confidence=HIGH
28 )
Path 2: 77 calls (0.06)
Import (46) ImportFrom (31)
None (46) 're' (9) 'collections' (7) 'sys' (3) '' (2) 'unknown' (1) 'neighbor_module' (1) 'math' (1) 'lala' (1) 'butchery' (1)
None (75) 1 (2)
1def _check_reimport(
2 self,
3 node: ImportNode,
4 basename: str | None = None,
5 level: int | None = None,
6 ) -> None:
7 """Check if a module with the same name is already imported or aliased."""
8 if not self.linter.is_message_enabled(
9 "reimported"
10 ) and not self.linter.is_message_enabled("shadowed-import"):
11 return
12
13 frame = node.frame(future=True)
14 root = node.root()
15 contexts = [(frame, level)]
16 if root is not frame:
17 contexts.append((root, None))
18
19 for known_context, known_level in contexts:
20 for name, alias in node.names:
21 first, msg = _get_first_import(
22 node, known_context, name, basename, known_level, alias
23 )
24 if first is not None and msg is not None:
25 name = name if msg == "reimported" else alias
26 self.add_message(
27 msg, node=node, args=(name, first.fromlineno), confidence=HIGH
28 )
Path 3: 53 calls (0.04)
Import (33) ImportFrom (20)
None (33) 'c' (3) 'd' (3) 'lower_level.helper_function' (2) 'deprecated' (1) 'functional.s.syntax.syntax_error' (1) 'typing' (1) 'some_module' (1) 'st...
None (43) 1 (9) 2 (1)
None (53)
1def _check_reimport(
2 self,
3 node: ImportNode,
4 basename: str | None = None,
5 level: int | None = None,
6 ) -> None:
7 """Check if a module with the same name is already imported or aliased."""
8 if not self.linter.is_message_enabled(
9 "reimported"
10 ) and not self.linter.is_message_enabled("shadowed-import"):
11 return
12
13 frame = node.frame(future=True)
14 root = node.root()
15 contexts = [(frame, level)]
16 if root is not frame:
17 contexts.append((root, None))
18
19 for known_context, known_level in contexts:
20 for name, alias in node.names:
21 first, msg = _get_first_import(
22 node, known_context, name, basename, known_level, alias
23 )
24 if first is not None and msg is not None:
25 name = name if msg == "reimported" else alias
26 self.add_message(
27 msg, node=node, args=(name, first.fromlineno), confidence=HIGH
28 )
Path 4: 47 calls (0.04)
ImportFrom (25) Import (22)
None (22) 'foo.bar' (4) '' (2) 'functools' (2) '_city' (1) 'city' (1) 'private_import.other_file' (1) 'astroid' (1) 'sys' (1) 'other_file' (1)
None (42) 1 (3) 2 (2)
1def _check_reimport(
2 self,
3 node: ImportNode,
4 basename: str | None = None,
5 level: int | None = None,
6 ) -> None:
7 """Check if a module with the same name is already imported or aliased."""
8 if not self.linter.is_message_enabled(
9 "reimported"
10 ) and not self.linter.is_message_enabled("shadowed-import"):
11 return
12
13 frame = node.frame(future=True)
14 root = node.root()
15 contexts = [(frame, level)]
16 if root is not frame:
17 contexts.append((root, None))
18
19 for known_context, known_level in contexts:
20 for name, alias in node.names:
21 first, msg = _get_first_import(
22 node, known_context, name, basename, known_level, alias
23 )
24 if first is not None and msg is not None:
25 name = name if msg == "reimported" else alias
26 self.add_message(
27 msg, node=node, args=(name, first.fromlineno), confidence=HIGH
28 )
Path 5: 6 calls (0.0)
Import (5) ImportFrom (1)
None (5) 'os' (1)
None (6)
1def _check_reimport(
2 self,
3 node: ImportNode,
4 basename: str | None = None,
5 level: int | None = None,
6 ) -> None:
7 """Check if a module with the same name is already imported or aliased."""
8 if not self.linter.is_message_enabled(
9 "reimported"
10 ) and not self.linter.is_message_enabled("shadowed-import"):
11 return
12
13 frame = node.frame(future=True)
14 root = node.root()
15 contexts = [(frame, level)]
16 if root is not frame:
17 contexts.append((root, None))
18
19 for known_context, known_level in contexts:
20 for name, alias in node.names:
21 first, msg = _get_first_import(
22 node, known_context, name, basename, known_level, alias
23 )
24 if first is not None and msg is not None:
25 name = name if msg == "reimported" else alias
26 self.add_message(
27 msg, node=node, args=(name, first.fromlineno), confidence=HIGH
28 )