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

[BUG] import xxx.yyy as zzz broken with language_level=2 (regression from 0.29.x) #5308

Closed
da-woods opened this issue Mar 10, 2023 · 3 comments · Fixed by #5329
Closed

[BUG] import xxx.yyy as zzz broken with language_level=2 (regression from 0.29.x) #5308

da-woods opened this issue Mar 10, 2023 · 3 comments · Fixed by #5329

Comments

@da-woods
Copy link
Contributor

da-woods commented Mar 10, 2023

Describe the bug

See code... Note that I compile with language_level 2

Code to reproduce the behaviour:

# testmod/cabc.pyx

import collections.abc as collections_abc
print(collections_abc)

Add an empty __init__.py to testmod (not sure if this is absolutely needed)

Compile with python3 cythonize.py -2if testmod/cabc.pyx && python3 -c "import testmod.cabc"

On the current master this print the collections module

Expected behaviour

It should print the collections.abc module (and it does on the 0.29 branch)

OS

Linux

Python version

>3

Cython version

current master

Additional context

Bisected to 4993ba6

@scoder
Copy link
Contributor

scoder commented Mar 14, 2023

This seems a critical bug that we should fix for beta-2. I expect quite a number of projects to keep their existing code base on language_level=2 at least in the beginning. It should be a viable migration path.

@da-woods
Copy link
Contributor Author

Agree. I'm actually quite surprised that this has been missed until now, suggesting few people are using language_level=2 explicitly. But quite a few "bugs" on the fedora list looked like they'd be solved by language_level 2

@scoder
Copy link
Contributor

scoder commented Mar 21, 2023

Well, there is a test for this that runs in both language levels:
https://github.com/cython/cython/blob/master/tests/run/importas.pyx
What seems to be missing is the same thing from within a package. It's a bit tricky now that there are two implementations (__Pyx_Import() and __Pyx_ImportDottedModule()) which both seem needed for the LL2 case since it combines that Py2 preference for relative imports with an absolute import fallback.

I'm looking into it.

scoder added a commit to scoder/cython that referenced this issue Mar 21, 2023
Since cython@4993ba6,
we returned the top-level package module instead of the module that was actually imported
with its dotted name ("collections" instead of "collections.abc").

Closes cython#5308
See cython#2854
scoder added a commit to scoder/cython that referenced this issue Mar 21, 2023
Since cython@4993ba6,
we returned the top-level package module instead of the module that was actually imported
with its dotted name ("collections" instead of "collections.abc").

Closes cython#5308
See cython#2854
scoder added a commit that referenced this issue Mar 22, 2023
GH-5329)

Since 4993ba6,
we returned the top-level package module instead of the module that was actually imported
with its dotted name ("collections" instead of "collections.abc").

Closes #5308
See #2854
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants