Method: pylint.extensions.private_import.PrivateImportChecker.visit_importfrom
Calls: 36, Exceptions: 0, Paths: 6Back
Path 1: 9 calls (0.25)
ImportFrom (9)
None (9)
1@utils.only_required_for_messages("import-private-name")
2 def visit_importfrom(self, node: nodes.ImportFrom) -> None:
3 if utils.is_node_in_typing_guarded_import_block(node):
4 return
5 # Only check imported names if the module is external
6 if self.same_root_dir(node, node.modname):
7 return
8
9 names = [n[0] for n in node.names]
10
11 # Check the imported objects first. If they are all valid type annotations, the package can be private
12 private_names = self._get_type_annotation_names(node, names)
13 if not private_names:
14 return
15
16 # There are invalid imported objects, so check the name of the package
17 private_module_imports = self._get_private_imports([node.modname])
18 private_module_imports = self._get_type_annotation_names(
19 node, private_module_imports
20 )
21 if private_module_imports:
22 self.add_message(
23 "import-private-name",
24 node=node,
25 args=("module", private_module_imports[0]),
26 confidence=HIGH,
27 )
28 return # Do not emit messages on the objects if the package is private
29
30 private_names = self._get_private_imports(private_names)
31
32 if private_names:
33 imported_identifier = "objects" if len(private_names) > 1 else "object"
34 private_name_string = ", ".join(private_names)
35 self.add_message(
36 "import-private-name",
37 node=node,
38 args=(imported_identifier, private_name_string),
39 confidence=HIGH,
40 )
Path 2: 7 calls (0.19)
ImportFrom (7)
None (7)
1@utils.only_required_for_messages("import-private-name")
2 def visit_importfrom(self, node: nodes.ImportFrom) -> None:
3 if utils.is_node_in_typing_guarded_import_block(node):
4 return
5 # Only check imported names if the module is external
6 if self.same_root_dir(node, node.modname):
7 return
8
9 names = [n[0] for n in node.names]
10
11 # Check the imported objects first. If they are all valid type annotations, the package can be private
12 private_names = self._get_type_annotation_names(node, names)
13 if not private_names:
14 return
15
16 # There are invalid imported objects, so check the name of the package
17 private_module_imports = self._get_private_imports([node.modname])
18 private_module_imports = self._get_type_annotation_names(
19 node, private_module_imports
20 )
21 if private_module_imports:
22 self.add_message(
23 "import-private-name",
24 node=node,
25 args=("module", private_module_imports[0]),
26 confidence=HIGH,
27 )
28 return # Do not emit messages on the objects if the package is private
29
30 private_names = self._get_private_imports(private_names)
31
32 if private_names:
33 imported_identifier = "objects" if len(private_names) > 1 else "object"
34 private_name_string = ", ".join(private_names)
35 self.add_message(
36 "import-private-name",
37 node=node,
38 args=(imported_identifier, private_name_string),
39 confidence=HIGH,
40 )
Path 3: 7 calls (0.19)
ImportFrom (7)
1@utils.only_required_for_messages("import-private-name")
2 def visit_importfrom(self, node: nodes.ImportFrom) -> None:
3 if utils.is_node_in_typing_guarded_import_block(node):
4 return
5 # Only check imported names if the module is external
6 if self.same_root_dir(node, node.modname):
7 return
8
9 names = [n[0] for n in node.names]
10
11 # Check the imported objects first. If they are all valid type annotations, the package can be private
12 private_names = self._get_type_annotation_names(node, names)
13 if not private_names:
14 return
15
16 # There are invalid imported objects, so check the name of the package
17 private_module_imports = self._get_private_imports([node.modname])
18 private_module_imports = self._get_type_annotation_names(
19 node, private_module_imports
20 )
21 if private_module_imports:
22 self.add_message(
23 "import-private-name",
24 node=node,
25 args=("module", private_module_imports[0]),
26 confidence=HIGH,
27 )
28 return # Do not emit messages on the objects if the package is private
29
30 private_names = self._get_private_imports(private_names)
31
32 if private_names:
33 imported_identifier = "objects" if len(private_names) > 1 else "object"
34 private_name_string = ", ".join(private_names)
35 self.add_message(
36 "import-private-name",
37 node=node,
38 args=(imported_identifier, private_name_string),
39 confidence=HIGH,
40 )
Path 4: 5 calls (0.14)
ImportFrom (5)
1@utils.only_required_for_messages("import-private-name")
2 def visit_importfrom(self, node: nodes.ImportFrom) -> None:
3 if utils.is_node_in_typing_guarded_import_block(node):
4 return
5 # Only check imported names if the module is external
6 if self.same_root_dir(node, node.modname):
7 return
8
9 names = [n[0] for n in node.names]
10
11 # Check the imported objects first. If they are all valid type annotations, the package can be private
12 private_names = self._get_type_annotation_names(node, names)
13 if not private_names:
14 return
15
16 # There are invalid imported objects, so check the name of the package
17 private_module_imports = self._get_private_imports([node.modname])
18 private_module_imports = self._get_type_annotation_names(
19 node, private_module_imports
20 )
21 if private_module_imports:
22 self.add_message(
23 "import-private-name",
24 node=node,
25 args=("module", private_module_imports[0]),
26 confidence=HIGH,
27 )
28 return # Do not emit messages on the objects if the package is private
29
30 private_names = self._get_private_imports(private_names)
31
32 if private_names:
33 imported_identifier = "objects" if len(private_names) > 1 else "object"
34 private_name_string = ", ".join(private_names)
35 self.add_message(
36 "import-private-name",
37 node=node,
38 args=(imported_identifier, private_name_string),
39 confidence=HIGH,
40 )
Path 5: 5 calls (0.14)
ImportFrom (5)
None (5)
1@utils.only_required_for_messages("import-private-name")
2 def visit_importfrom(self, node: nodes.ImportFrom) -> None:
3 if utils.is_node_in_typing_guarded_import_block(node):
4 return
5 # Only check imported names if the module is external
6 if self.same_root_dir(node, node.modname):
7 return
8
9 names = [n[0] for n in node.names]
10
11 # Check the imported objects first. If they are all valid type annotations, the package can be private
12 private_names = self._get_type_annotation_names(node, names)
13 if not private_names:
14 return
15
16 # There are invalid imported objects, so check the name of the package
17 private_module_imports = self._get_private_imports([node.modname])
18 private_module_imports = self._get_type_annotation_names(
19 node, private_module_imports
20 )
21 if private_module_imports:
22 self.add_message(
23 "import-private-name",
24 node=node,
25 args=("module", private_module_imports[0]),
26 confidence=HIGH,
27 )
28 return # Do not emit messages on the objects if the package is private
29
30 private_names = self._get_private_imports(private_names)
31
32 if private_names:
33 imported_identifier = "objects" if len(private_names) > 1 else "object"
34 private_name_string = ", ".join(private_names)
35 self.add_message(
36 "import-private-name",
37 node=node,
38 args=(imported_identifier, private_name_string),
39 confidence=HIGH,
40 )
Path 6: 3 calls (0.08)
ImportFrom (3)
None (3)
1@utils.only_required_for_messages("import-private-name")
2 def visit_importfrom(self, node: nodes.ImportFrom) -> None:
3 if utils.is_node_in_typing_guarded_import_block(node):
4 return
5 # Only check imported names if the module is external
6 if self.same_root_dir(node, node.modname):
7 return
8
9 names = [n[0] for n in node.names]
10
11 # Check the imported objects first. If they are all valid type annotations, the package can be private
12 private_names = self._get_type_annotation_names(node, names)
13 if not private_names:
14 return
15
16 # There are invalid imported objects, so check the name of the package
17 private_module_imports = self._get_private_imports([node.modname])
18 private_module_imports = self._get_type_annotation_names(
19 node, private_module_imports
20 )
21 if private_module_imports:
22 self.add_message(
23 "import-private-name",
24 node=node,
25 args=("module", private_module_imports[0]),
26 confidence=HIGH,
27 )
28 return # Do not emit messages on the objects if the package is private
29
30 private_names = self._get_private_imports(private_names)
31
32 if private_names:
33 imported_identifier = "objects" if len(private_names) > 1 else "object"
34 private_name_string = ", ".join(private_names)
35 self.add_message(
36 "import-private-name",
37 node=node,
38 args=(imported_identifier, private_name_string),
39 confidence=HIGH,
40 )