Skip to content

Duplicate module named "__main__" #23

Open

Description

@jaraco

After #22, tests throughout are experiencing this error:

______________________________________________________________________ [mypy] __main__.py _______________________________________________________________________
__main__.py: error: Duplicate module named "__main__" (also at "__init__.py")
__main__.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
__main__.py: note: Common resolutions include:
__main__.py: note:     a) using `--exclude` to avoid checking one of them,
__main__.py: note:     b) adding `__init__.py` somewhere,
__main__.py: note:     c) using `--explicit-package-bases` or adjusting `MYPYPATH`

In the PR, I'd encountered the error, but thought it was fixed with the monkey patch. What's gone wrong?

Activity

  1. jaraco commented on May 25, 2026

    @jaraco
    MemberAuthor

    Aha, so the issue only manifests now when coherent.test is installed under pip-run and the coherent.test entry point.

  2. jaraco commented on May 25, 2026

    @jaraco
    MemberAuthor

    Aha, so the issue only manifests now when coherent.test is installed under pip-run and the coherent.test entry point.

    Duh. That's because the mypy.ini isn't generated without that change.

    After adding that manually, I'm able to replicate the issue in a venv with -e .[test] installed using py -m pytest.

  3. jaraco commented on May 25, 2026

    @jaraco
    MemberAuthor

    Aha. I figured out the issue.

    Mypy provides its behavior through optimized, generated C files, so when running --editable, the monkey patching works as intended, but when run from a binary install (or other optimized build), the monkey patch never has any effect. Moreover, it seems not to be possible to disable the use of the compiled sources easily.

    It looks like it may be possible to delete the mypy extension sources by looking at importlib.machinery.EXTENSION_SUFFIXES and deleting all such files in the mypy install (which is temporary anyway).

    Or maybe we should switch to pyrefly or ty for type checking (if either has a pytest plugin).

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions