Skip to content

fast parser: # type: ignore should ignore non-* imports entirely #1739

@rwbarton

Description

@rwbarton

The parse_file function from the old parser does this:

        # Skip imports that have been ignored (so that we can ignore a C extension module without
        # stub, for example), except for 'from x import *', because we wouldn't be able to
        # determine which names should be defined unless we process the module. We can still
        # ignore errors such as redefinitions when using the latter form.
        imports = [node for node in self.imports
                   if node.line not in self.ignored_lines or isinstance(node, ImportAll)]
        node = MypyFile(defs, imports, is_bom, self.ignored_lines,
                        weak_opts=weak_opts)

The effect is that a # type: ignore comment on an import statement doesn't just silence errors on that line, but also prevents mypy from trying to process the imported module at all.

The fast parser should do the same thing.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions