Path 1: 1188 calls (0.93)

ImportFrom (625) Import (563)

None (1188)

1def _check_toplevel(self, node: ImportNode) -> None:
2        """Check whether the import is made outside the module toplevel."""
3        # If the scope of the import is a module, then obviously it is
4        # not outside the module toplevel.
5        if isinstance(node.scope(), nodes.Module):
6            return
7
8        module_names = [
9            f"{node.modname}.{name[0]}"
10            if isinstance(node, nodes.ImportFrom)
11            else name[0]
12            for name in node.names
13        ]
14
15        # Get the full names of all the imports that are only allowed at the module level
16        scoped_imports = [
17            name for name in module_names if name not in self._allow_any_import_level
18        ]
19
20        if scoped_imports:
21            self.add_message(
22                "import-outside-toplevel", args=", ".join(scoped_imports), node=node
23            )
            

Path 2: 82 calls (0.06)

Import (50) ImportFrom (32)

1def _check_toplevel(self, node: ImportNode) -> None:
2        """Check whether the import is made outside the module toplevel."""
3        # If the scope of the import is a module, then obviously it is
4        # not outside the module toplevel.
5        if isinstance(node.scope(), nodes.Module):
6            return
7
8        module_names = [
9            f"{node.modname}.{name[0]}"
10            if isinstance(node, nodes.ImportFrom)
11            else name[0]
12            for name in node.names
13        ]
14
15        # Get the full names of all the imports that are only allowed at the module level
16        scoped_imports = [
17            name for name in module_names if name not in self._allow_any_import_level
18        ]
19
20        if scoped_imports:
21            self.add_message(
22                "import-outside-toplevel", args=", ".join(scoped_imports), node=node
23            )
            

Path 3: 1 calls (0.0)

Import (1)

1def _check_toplevel(self, node: ImportNode) -> None:
2        """Check whether the import is made outside the module toplevel."""
3        # If the scope of the import is a module, then obviously it is
4        # not outside the module toplevel.
5        if isinstance(node.scope(), nodes.Module):
6            return
7
8        module_names = [
9            f"{node.modname}.{name[0]}"
10            if isinstance(node, nodes.ImportFrom)
11            else name[0]
12            for name in node.names
13        ]
14
15        # Get the full names of all the imports that are only allowed at the module level
16        scoped_imports = [
17            name for name in module_names if name not in self._allow_any_import_level
18        ]
19
20        if scoped_imports:
21            self.add_message(
22                "import-outside-toplevel", args=", ".join(scoped_imports), node=node
23            )