Skip to content

Unreachable imports not ignored in methods #4324

@JukkaL

Description

@JukkaL

The second import xxx as os generates an error, though it's similar to the first import, which doesn't generate an error:

import sys

def f() -> None:
    if sys.platform == 'xyz':  # Nonsensical platform
        import xxx as os  # No error
    else:
        import os

class A:
    def g(self) -> None:
        if sys.platform == 'xyz':
            import xxx as os  # Error
        else:
            import os

The culprit is semantic analyzer pass 1, which only recurses into top-level functions but not into methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions