Skip to content

'from .foo import *' introduces 'foo' as symbol that mypy doesn't recognise #4140

Closed
@Wilfred

Description

@Wilfred

The typeshed definition for yaml/__init__.pyi contains the following (src):

from yaml.error import *

This has two side effects: it adds every symbol foo in yaml/error.py as yaml.foo. However, it also defines yaml.error.

I believe this is why the mypy complains about the following correct code:

import yaml

def foo():
    # type: () -> None
    yaml.error
$ mypy --py2 foo.py
foo.py:5: error: Module has no attribute "error"

Oddly, I can't reproduce this on Python 3. The following code does not produce a type error:

import yaml

def foo() -> None:
    yaml.error

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