Skip to content

Support packages spread over multiple directories via __path__ manipulation #1456

@JukkaL

Description

@JukkaL

It's possible to manipulate __path__ in packages to let a package span multiple directories. For example, some files of package p.q can be in x/p/q and remaining files are in y/p/q. It's difficult to detect this automatically, but we could support a special entry in MYPYPATH for this:

export MYPYPATH=package(p.q,x,y)

(I'm working on some internal Dropbox code that uses this idiom.)

Any positive number of directories can be included. By including a single directory, it's possible to only pick a particular module/package from a site packages directory. This can be useful for third party modules that are annotated and don't have stubs in typeshed. Including the entire site packages directory in MYPYPATH would likely result in mypy getting very confused, as most of the code would probably not be mypy compatible. Example:

export MYPYPATH=package(mypackage,/path/site-packages)

Spaces around entries within package(...) should be stripped.

This is followup to #1422 and based on an offline discussion we had a while back.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions