Skip to content

Duplicate module names causes Module has no attribute #8220

Closed as not planned

Description

@plannigan

This is a bug report. There was a regression recently that caused mypy to start raising error where it did not in the past.

Example:
Save the following code at pathlib.py.

import pathlib

p = pathlib.Path(".")
print(p)

With the latest mypy, this fails.

$ mypy --version
mypy 0.761
$ mypy pathlib.py 
pathlib.py:3: error: Module has no attribute "Path"
Found 1 error in 1 file (checked 1 source file)

However, it used to work:

$ mypy --version
mypy 0.720
$ mypy pathlib.py 
$ 

Note: This code won't run, but I was having trouble making a simple example to reproduce the issue I was seeing. The actually case where this happened does work and was a sub-module within a project that was named the same as a 3rd part module it was wrapping.

Activity

  1. erictraut commented on Aug 11, 2023

    @erictraut

    This appears to have been fixed at some point. The latest version of mypy no longer emits an error for the code sample.

  2. hauntsaninja commented on Aug 12, 2023

    @hauntsaninja
    Collaborator

    It actually does still repro for me (the repro depends on the name of the file). But this behaviour is desirable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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