Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`from . cimport modulename` tries to search in parent package from `__init__.pxd`. #3442

Open
will-ca opened this issue Mar 17, 2020 · 0 comments

Comments

@will-ca
Copy link
Contributor

@will-ca will-ca commented Mar 17, 2020

In __init__.pxd in a package, using from . cimport modulename attempts to find modulename.pxd in the parent directory of the package.

Using from . import modulename in basic Python attempts to find modulename.* within the package itself, as does using from . cimport modulename in all *.pxd files except for __init__.pxd in packages.

Using from .packagename cimport modulename in __init__.pxd doesn't work around this, because this (correctly) attempts to find packagename inside the package itself.

Because of this, I think there should not be much functional code out there that depends on the relative cimport being based on the parent directory, meaning that it should be possible to switch it to the package directory, in line with Python behaviour, without breaking compatibility.


Example structure:

cyrel_package/
├── __init__.pxd
├── __init__.py
├── module.pxd
├── module.py
└── subpackage
    ├── __init__.pxd
    ├── __init__.py
    ├── submodule.pxd
    └── submodule.py

And in cyrel_package/subpackage/__init__.pxd:

# from . cimport submodule
# Fails, "'cyrel_package/submodule.pxd' not found" — Attempts to import relative to parent package directory instead of current package directory.

# from .subpackage cimport submodule
# Fails, "'cyrel_package/subpackage/subpackage/submodule.pxd' not found" — Attempts to (correctly) import relative to current package directory.

from cyrel_package.subpackage cimport submodule
# Works.

It also fails with from . cimport module in the topmost cyrel_package/__init__.pxd.

@will-ca will-ca changed the title `from . cimport modulename` tries to search from parent package in `__init__.pxd`. `from . cimport modulename` tries to search in parent package from `__init__.pxd`. Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.