Path 1: 305 calls (0.2)

ImportFrom (229) Import (76)

Module (300) FunctionDef (5)

'Union' (10) 'TypedDict' (9) 'sys' (8) 'List' (8) 'Optional' (8) 'Callable' (7) 'Dict' (7) 'TYPE_CHECKING' (6) 'NoReturn' (6) 'os' (6)

'typing' (88) None (76) 'pylint' (13) 'unittest.mock' (11) 'collections' (9) 'classes' (6) 'collections.abc' (6) 'dataclasses' (5) 'sys' (5) '' (4)

None (297) 1 (8)

None (289) 'Reporter' (3) 'foobar' (2) 'libalgos' (2) 't' (2) 'foo' (1) 'bar2' (1) '_re' (1) 'second' (1) 'test2' (1)

(None, None) (305)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 2: 248 calls (0.16)

ImportFrom (149) Import (99)

Module (242) FunctionDef (6)

'annotations' (19) 'typing' (11) 'collections' (11) 'six' (10) 'abc' (9) 'sys' (8) 'abstractmethod' (8) 'Enum' (7) 'ABCMeta' (7) 'dataclasses' (5)

None (99) 'typing' (32) '__future__' (24) 'abc' (17) 'enum' (12) 'collections' (8) 'unknown' (7) 'dataclasses' (7) 'UNINFERABLE' (5) 'os' (4)

None (244) 1 (4)

None (242) 'renamed_logging' (1) 'PyEnum' (1) 'np' (1) 'plt' (1) 'nonseq_func' (1) 'PATH' (1)

(None, None) (248)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 3: 156 calls (0.1)

ImportFrom (79) Import (77)

Module (110) FunctionDef (46)

'print_function' (13) 'error' (10) 'logging' (10) 're' (9) 'os' (7) 'argparse' (6) 'collections' (5) 'sys' (5) 'TypeVar' (5) 'THING1' (4)

None (77) '__future__' (17) 'typing' (10) 're' (9) '' (4) 'thing1' (2) 'all_the_things' (2) 'sys' (2) 'os.path' (2) 'optparse' (2)

None (144) 1 (11) 3 (1)

None (148) 'renamed_logging' (2) 'łos' (2) 'OrderedDict' (1) 'blogging' (1) 'ass' (1) 'abc' (1)

(None, None) (156)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 4: 145 calls (0.09)

Import (84) ImportFrom (61)

Module (139) FunctionDef (5) ClassDef (1)

'os' (24) 'nonexistent' (21) 'abc' (10) 'Enum' (6) 'Any' (4) 'sys' (4) 'asyncio' (3) 'annotations' (3) 'ABCMeta' (3) 'print_function' (2)

None (84) 'typing' (16) 'enum' (7) '__future__' (6) 'functools' (6) 'data.suppliermodule_test' (6) 'abc' (5) 'collections' (3) 'UNINFERABLE' (2) 'data...

None (144) 2 (1)

None (143) '__annotations__' (1) 'ExtensionProtocol' (1)

(None, None) (145)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 5: 125 calls (0.08)

Import (74) ImportFrom (51)

Module (123) FunctionDef (2)

'typing' (12) 'collections.abc' (4) 'sys' (4) 'six' (4) 'contextlib' (3) 'Callable' (3) 'TYPE_CHECKING' (3) 'Union' (3) 'collections' (3) 're' (3)

None (74) 'typing' (19) 'dataclasses' (3) 'collections.abc' (3) 'unknown' (3) 'enum' (3) 'pathlib' (3) 'ala_bala_portocola' (2) 'concurrent.futures' (...

None (125)

None (116) 'pd' (2) 'keyword_only' (1) 'logging' (1) 'ok' (1) 'foobar' (1) 'test_cp' (1) 'test' (1) 'CollectionCounter' (1)

(None, None) (125)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 6: 111 calls (0.07)

ImportFrom (70) Import (41)

Module (109) FunctionDef (2)

'typing' (8) 'logging' (5) 'Callable' (4) 'Union' (4) 'dataclasses' (3) 'List' (3) 'Optional' (3) 'dataclass' (3) 'Any' (3) 'os' (3)

None (41) 'typing' (29) 'city' (6) 'dataclasses' (6) 'thing2' (4) 'collections' (4) 'missing' (3) 'lala' (2) 'collections.abc' (2) 'functional.u.unpac...

None (107) 1 (4)

None (101) 'dc' (2) 'renamed_logging' (2) 't' (2) 'te' (2) 'path' (1) 'OS' (1)

(None, None) (111)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 7: 66 calls (0.04)

Import (36) ImportFrom (30)

Module (65) FunctionDef (1)

're' (10) 'error' (10) 'unknown' (2) 'urllib2' (2) 'sys' (2) 'argparse' (2) 'optparse' (2) 'get_cache_token' (2) 'exit' (1) 'LocalException' (1)

None (36) 're' (9) '_abc' (8) 'urllib' (2) 'collections' (2) '_py_abc' (2) 'unknown' (1) 'sys' (1) 'neighbor_module' (1) 'urlparse' (1)

None (66)

None (59) 'urllib_request' (2) 'urllib_error' (2) 'js' (2) 'pd' (1)

(None, None) (66)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 8: 58 calls (0.04)

ImportFrom (34) Import (24)

Module (58)

'os' (8) 'math' (4) 'random' (4) 'are_exclusive' (3) 'delete' (2) 'get' (2) 'head' (2) 'options' (2) 'patch' (2) 'post' (2)

None (24) 'requests' (16) 'threading' (5) 'astroid' (4) 'typing' (3) 'importlib.machinery' (2) '__future__' (1) 'collections' (1) 'distutils.util' (1)...

None (58)

None (49) 'logging' (1) 'delete_r' (1) 'get_r' (1) 'head_r' (1) 'options_r' (1) 'patch_r' (1) 'post_r' (1) 'put_r' (1) 'request_r' (1)

(None, None) (58)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 9: 34 calls (0.02)

Import (25) ImportFrom (9)

Module (19) FunctionDef (15)

'os' (8) 'optparse' (2) 'socket' (2) '*' (2) 'threading.current_thread' (1) 'distutils' (1) 'xml.etree.cElementTree' (1) 'imp' (1) 'generators' (1) 's...

None (25) 'math' (2) 'empty' (2) '__future__' (1) 'collections' (1) 'os' (1) '' (1) 'double_name' (1)

None (32) 1 (1) 3 (1)

None (25) 'os' (4) 'thyme' (1) 'rand' (1) 'sock' (1) 'sign' (1) 'cosplay' (1)

(None, None) (34)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 10: 31 calls (0.02)

Import (19) ImportFrom (12)

Module (31)

'_TreeType' (3) 'collections.missing' (2) 'collections.emit1' (2) 'Literal' (2) 'TreeType' (1) 'something' (1) 'anything' (1) 'collections.indeed_miss...

None (19) 'collections' (3) '_types' (2) 'typing' (2) 'types' (1) '' (1) 'pprint' (1) 'typing_extensions' (1) 'pylint.lint' (1)

None (30) 1 (1)

None (31)

(None, None) (31)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 11: 27 calls (0.02)

ImportFrom (23) Import (4)

Module (27)

'Missing' (12) 'Unknown' (2) 'Dict' (1) 'NoReturn' (1) 'ClassVar' (1) 'Portocala' (1) 'ctypes' (1) 'overload' (1) 'dataclass' (1) 'ABCMeta' (1)

'missing' (12) 'typing' (4) None (4) 'unknown' (1) 'ala' (1) 'Unknown' (1) 'dataclasses' (1) 'abc' (1) 'a' (1) 'graphlib' (1)

None (26) 1 (1)

None (27)

(None, None) (27)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 12: 26 calls (0.02)

ImportFrom (15) Import (11)

Module (26)

'w0401_cycle' (2) 'xml' (2) 'datetime' (2) 'Enum' (1) 'Decimal' (1) 'c_int' (1) 'matplotlib.pyplot' (1) 'unittest.case' (1) 'wraps' (1) 'namedtuple' (...

None (11) '' (3) 'collections' (2) 'string' (2) 'sys' (2) 'enum' (1) 'decimal' (1) 'ctypes' (1) 'functools' (1) 'os' (1)

None (25) 3 (1)

None (19) 'plt' (1) 'sql' (1) 'abc' (1) 'PATH' (1) 'OS' (1) 'VERSION' (1) 'RE' (1)

(None, None) (26)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 13: 20 calls (0.01)

ImportFrom (18) Import (2)

Module (19) FunctionDef (1)

'Protocol' (3) 'dataclass' (2) 'List' (2) 'IntEnum' (1) 'log10' (1) 'uninstalled' (1) 'overload' (1) 'Missing' (1) 'Any' (1) 'Dict' (1)

'typing' (9) None (2) 'enum' (1) 'math' (1) 'pydantic.dataclasses' (1) 'missing' (1) 'dataclasses' (1) 'collections' (1) 'another' (1) 'pylint.lint' (...

None (18) 1 (2)

None (20)

(None, None) (20)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 14: 20 calls (0.01)

ImportFrom (13) Import (7)

Module (20)

'Protocol' (6) 'sys' (2) 'os' (2) 'deque' (2) 'socket' (1) 'defaultdict' (1) 'namedtuple' (1) 're' (1) 'List' (1) 'package4' (1)

None (7) 'collections' (4) 'typing' (4) 'typing_extensions' (3) '' (1) 'random' (1)

None (19) 1 (1)

None (20)

(None, None) (20)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 15: 19 calls (0.01)

Import (16) ImportFrom (3)

Module (19)

'os' (2) 'ast' (1) 'symtable' (1) 'sys' (1) 'time' (1) 'random' (1) 'socket' (1) 'tokenize' (1) 'trace' (1) 'tabnanny' (1)

None (16) 'math' (2) 'collections' (1)

None (19)

None (13) 'thyme' (1) 'rand' (1) 'sock' (1) 'sign' (1) 'cosplay' (1) 'configparser' (1)

(None, None) (19)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 16: 16 calls (0.01)

ImportFrom (13) Import (3)

Module (15) FunctionDef (1)

'logging.handlers' (1) 'foo' (1) 'Unknown' (1) 'Enum' (1) 'Any' (1) 'Dict' (1) 'BaseModel' (1) 'nope' (1) 'get_module_part' (1) 'is_standard_module' (...

None (3) 'typing' (3) 'astroid.modutils' (2) 'first_party.bar' (1) 'unknown' (1) 'enum' (1) 'pydantic' (1) 'distutils.doesnottexists' (1) 'xyz' (1) 'm...

None (15) 1 (1)

None (15) 'RE' (1)

(None, None) (16)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 17: 12 calls (0.01)

ImportFrom (12)

Module (12)

'func_w0401' (5) 'w0401_cycle' (4) 'var' (2) 'data' (1)

'' (10) 'b' (2)

1 (12)

None (12)

(None, None) (12)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 18: 11 calls (0.01)

ImportFrom (10) Import (1)

Module (11)

'singledispatch' (2) 'configparser' (2) 'datetime' (1) 'Literal' (1) 'Counter' (1) 'OrderedDict' (1) 'defaultdict' (1) 'UserDict' (1) 'GenericAlias' (...

'collections' (4) 'functools' (1) 'singledispatch' (1) 'datetime' (1) 'typing_extensions' (1) 'types' (1) 'six.moves' (1) None (1)

None (11)

None (11)

(None, None) (11)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 19: 10 calls (0.01)

Import (7) ImportFrom (3)

Module (10)

'foobar' (2) 'sys' (2) '_chair' (1) '_stair' (1) 'os' (1) 're' (1) 'ElementTree' (1) 'typing' (1)

None (7) 'foo.bar' (2) 'xml.etree' (1)

None (10)

None (6) 'OS' (1) 'foobar' (1) 'foo' (1) 't' (1)

tuple (10)

GeneratorExit (10)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 20: 10 calls (0.01)

Import (7) ImportFrom (3)

Module (9) FunctionDef (1)

'argv' (2) 'collections' (1) 'time' (1) 'executable' (1) 're' (1) '__builtin__' (1) 'builtins' (1) 'os' (1) 'x' (1)

None (7) 'sys' (3)

None (10)

None (8) 'python' (1) 'builtins' (1)

(None, None) (10)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 21: 8 calls (0.01)

ImportFrom (8)

Module (8)

'_private' (2) 'bar' (2) 'NoSelfArgument' (1) 'Class' (1) 'Class3' (1) 'my_package' (1)

'' (3) 'parent' (1) 'foo' (1) 'no_self_argument' (1) 'package' (1) 'package3' (1)

1 (5) 2 (3)

None (6) 'bar' (2)

(None, None) (8)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 22: 7 calls (0.0)

Import (7)

Module (7)

'functools' (2) 'os' (2) 'copy' (2) 'typing' (1)

None (7)

None (7)

None (3) 'aliased_functools' (2) 'ass' (1) 'mytyping' (1)

tuple (7)

GeneratorExit (7)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 23: 6 calls (0.0)

ImportFrom (4) Import (2)

Module (6)

'_house' (2) 'a' (1) '_b' (1) 'c' (1) '_d' (1)

'_city' (4) None (2)

None (6)

None (6)

tuple (6)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 24: 6 calls (0.0)

Import (5) ImportFrom (1)

Module (5) FunctionDef (1)

'sys' (4) 'search' (1) 'xml' (1)

None (5) 're' (1)

None (6)

None (5) 'sql' (1)

(None, None) (6)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 25: 6 calls (0.0)

ImportFrom (4) Import (2)

Module (6)

'NoReturn' (2) 'are_exclusive' (1) 'sys' (1) 'OrderedDict' (1) 'ast' (1)

None (2) 'typing' (1) 'typing_extensions' (1) 'astroid' (1) 'collections' (1)

None (6)

None (6)

(None, None) (6)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 26: 5 calls (0.0)

ImportFrom (5)

Module (5)

'_private' (3) 'deque' (1) 'TYPE_CHECKING' (1)

'private_import.other_file' (1) 'astroid' (1) 'sys' (1) 'itertools' (1) 'io' (1)

None (5)

None (5)

tuple (5)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 27: 5 calls (0.0)

ImportFrom (5)

Module (5)

'bar' (2) 'foo2' (2) 'OrderedDict' (1)

'' (4) 'itertools' (1)

1 (4) None (1)

'Bar' (1) None (1) 'foo2' (1) 'bar2' (1) 'NotOrderedDict' (1)

(None, None) (5)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 28: 4 calls (0.0)

ImportFrom (3) Import (1)

Module (4)

'Bar' (2) 'nonexistant' (1) 'roles' (1)

'optparse' (2) None (1) 'nodes' (1)

1 (2) 2 (1) None (1)

None (4)

(None, None) (4)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 29: 4 calls (0.0)

Import (4)

Module (4)

'house' (1) 'math' (1) 'os.path' (1) 'missing1' (1)

None (4)

None (4)

None (2) '_' (1) 'p' (1)

tuple (4)

GeneratorExit (4)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 30: 4 calls (0.0)

ImportFrom (4)

Module (4)

'lru_cache' (1) 'cache' (1) 'final' (1) 'ABCMeta' (1)

'functools' (2) 'typing' (1) 'abc' (1)

None (4)

'aliased_cache' (2) 'myfinal' (1) 'SomethingElse' (1)

tuple (4)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 31: 3 calls (0.0)

ImportFrom (3)

Module (3)

'a' (1) 'c' (1) '_d' (1)

'city' (3)

None (3)

None (3)

tuple (3)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 32: 3 calls (0.0)

ImportFrom (2) Import (1)

Module (3)

'foo' (2) 'pandas.core.algorithms' (1)

'' (2) None (1)

1 (2) None (1)

'bar' (2) 'algos' (1)

tuple (3)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 33: 3 calls (0.0)

ImportFrom (3)

Module (3)

'*' (3)

'rie' (1) 'itertools' (1) 'os' (1)

None (3)

None (3)

(None, None) (3)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 34: 3 calls (0.0)

Import (2) ImportFrom (1)

Module (3)

'exists' (1) 'email.encoders' (1) 'pandas._libs.algos' (1)

None (2) 'os.path' (1)

None (3)

None (2) 'algos' (1)

tuple (3)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 35: 3 calls (0.0)

ImportFrom (3)

Module (3)

'*' (3)

'unused_import_py30' (1) 'unknown.package' (1) 'UNINFERABLE' (1)

None (2) 1 (1)

None (3)

(None, None) (3)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 36: 2 calls (0.0)

ImportFrom (2)

Module (2)

'LstT' (2)

'a' (2)

1 (2)

None (2)

(None, None) (2)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 37: 2 calls (0.0)

ImportFrom (2)

Module (2)

'OrderedDict' (1) 'Path' (1)

'collections' (1) 'pathlib' (1)

None (2)

'o_dict' (1) None (1)

tuple (2)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 38: 2 calls (0.0)

ImportFrom (2)

Module (2)

'foobar' (2)

'foo.bar' (2)

2 (2)

'foobar' (1) 'anotherfoobar' (1)

tuple (2)

GeneratorExit (2)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 39: 2 calls (0.0)

ImportFrom (2)

Module (2)

'open' (2)

'os' (2)

None (2)

None (2)

tuple (2)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 40: 2 calls (0.0)

ImportFrom (1) Import (1)

Module (2)

'CustomPath' (1) 'FastAPI.Path' (1)

'some_other_lib' (1) None (1)

None (2)

'Path' (2)

tuple (2)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 41: 2 calls (0.0)

ImportFrom (1) Import (1)

Module (2)

'CustomHello' (1) 'astroid' (1)

'goodbye' (1) None (1)

None (2)

'Hello' (1) 'typing' (1)

tuple (2)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 42: 2 calls (0.0)

Import (2)

Module (2)

'os' (2)

None (2)

None (2)

'o' (1) None (1)

tuple (2)

GeneratorExit (2)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 43: 2 calls (0.0)

ImportFrom (2)

Module (2)

'*' (2)

'unused_global_variable1' (1) 'abc' (1)

1 (1) None (1)

None (2)

(None, None) (2)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 44: 2 calls (0.0)

Import (2)

Module (2)

'time' (2)

None (2)

None (2)

None (2)

tuple (2)

GeneratorExit (2)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 45: 1 calls (0.0)

ImportFrom (1)

Module (1)

'_private' (1)

'other_file' (1)

1 (1)

None (1)

tuple (1)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None
            

Path 46: 1 calls (0.0)

ImportFrom (1)

Module (1)

'b' (1)

'a' (1)

12 (1)

None (1)

(None, None) (1)

1def _get_first_import(
2    node: ImportNode,
3    context: nodes.LocalsDictNodeNG,
4    name: str,
5    base: str | None,
6    level: int | None,
7    alias: str | None,
8) -> tuple[nodes.Import | nodes.ImportFrom | None, str | None]:
9    """Return the node where [base.]<name> is imported or None if not found."""
10    fullname = f"{base}.{name}" if base else name
11
12    first = None
13    found = False
14    msg = "reimported"
15
16    for first in context.body:
17        if first is node:
18            continue
19        if first.scope() is node.scope() and first.fromlineno > node.fromlineno:
20            continue
21        if isinstance(first, nodes.Import):
22            if any(fullname == iname[0] for iname in first.names):
23                found = True
24                break
25            for imported_name, imported_alias in first.names:
26                if not imported_alias and imported_name == alias:
27                    found = True
28                    msg = "shadowed-import"
29                    break
30            if found:
31                break
32        elif isinstance(first, nodes.ImportFrom):
33            if level == first.level:
34                for imported_name, imported_alias in first.names:
35                    if fullname == f"{first.modname}.{imported_name}":
36                        found = True
37                        break
38                    if (
39                        name != "*"
40                        and name == imported_name
41                        and not (alias or imported_alias)
42                    ):
43                        found = True
44                        break
45                    if not imported_alias and imported_name == alias:
46                        found = True
47                        msg = "shadowed-import"
48                        break
49                if found:
50                    break
51    if found and not astroid.are_exclusive(first, node):
52        return first, msg
53    return None, None