Skip to content

Namespace packages supported by default? #14057

Description

@jaraco

I notice in the changelog that 0.990 adds support for namespace packages by default.

I've been using mypy on namespace packages (jaraco, svg, backports, and others) for some time now (jaraco/skeleton@7455f2f).

With the release of mypy 0.990, however, tests have started failing across all projects with namespace packages:

error: Source file found twice under different module names: "collections" and "jaraco.collections"

The change log indicates that 0.990 adds support for namespace packages by default. Annoyingly, this change has had the opposite effect for my projects. I find that I can restore functionality by adding explicit_package_bases = True to the config file (or equivalent command line). It's slightly annoying to have to add this configuration to all of my projects just to support some projects with namespace packages.

Is it possible that explicit package bases will become default in the future?

Activity

  1. jaraco commented on Nov 10, 2022

    @jaraco
    MemberAuthor

    The reason why I ask is because in the current state, namespace packages get a second-class experience.

  2. reopened this on Nov 10, 2022
  3. hauntsaninja commented on Nov 10, 2022

    @hauntsaninja
    Collaborator

    We chose not to make it the default at the time it was introduced because doing so was very breaking, e.g. all packages with src layout would probably break. It still remains true that most Python packages are not namespace packages, so it feels hard to justify.

    (Not present in your report, but I believe the error message should currently suggest using --explicit-package-bases; let me know if that's not the case)

  4. removed their assignment
    on Nov 10, 2022
  5. jaraco commented on Nov 11, 2022

    @jaraco
    MemberAuthor

    Correct. The suggestion wasn’t apparent when running under pytest-mypy. Once I ran the tests using mypy directly, the suggestion was present and led me to the workaround.

  6. bryanforbes commented on Dec 1, 2022

    @bryanforbes
    Contributor

    There seems to be a related bug in Windows where mypy is not finding the stub files (which are included in the wheel) for backports.zoneinfo in Python 3.7 and 3.8. The reproduction is pretty simple:

    pip install mypy backports.zoneinfo
    mypy -c 'from backports import zoneinfo'

    This only occurs on Windows. It works fine on Linux and macOS.

  7. hauntsaninja commented on Dec 1, 2022

    @hauntsaninja
    Collaborator

    @AlexWaygood interested in looking at this issue? I don't have a windows system to reproduce

  8. AlexWaygood commented on Dec 1, 2022

    @AlexWaygood
    Member

    I can try to have a look, but no promises -- pretty busy at the moment :(

  9. jaraco commented on Mar 23, 2023

    @jaraco
    MemberAuthor

    There seems to be a related bug in Windows ...

    It may be related, but the bug as reported applies across platforms. It may be worthwhile to open a separate bug for the possibly related Windows-specific issue.

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

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions