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

[ENH] Compilation does not support importing cython module from another module #6129

Open
matusvalo opened this issue Apr 6, 2024 · 4 comments
Milestone

Comments

@matusvalo
Copy link
Contributor

matusvalo commented Apr 6, 2024

Is your feature request related to a problem? Please describe.

Consider following situation:

######## py_module.py #######
import cython
####### cy_module.py ########
from py_module import cython

def main():
    a: cython.int = 5
    print(a + 1)

When compiling Cython ignores cython.int annotation because it does not recognise cython module even though from Python semantics the correct cython module is imported.

Describe the solution you'd like.

Importing cython module recognise cython module during compilation even not imported directly. The behaviour will match python semantics.

Describe alternatives you've considered.

I suppose implementing this issue 100% correctly is complex - cython needs to execute real import and check whether cython module is cython's one. Maybe the initial sufficient solution is just to consider cython module imported when cython name is present in import:

  • from dummy import cython
  • from dummy.subdummy import cython
  • from dummy.cython import int

In all these cases, compiler will consider imported cython module even though it is never checked what is inside module.

Of coarse this logic will apply only for compilation and should be explicitly documented. Maybe this logic can be driven by a directive...

Additional context

This feature seems to be desired from users of cython - see:

@matusvalo matusvalo added this to the 3.1 milestone Apr 6, 2024
@da-woods
Copy link
Contributor

da-woods commented Apr 6, 2024

I think https://github.com/sqlalchemy/sqlalchemy/blob/d3222a31b8df97a454b37a32881dd484a06e5742/lib/sqlalchemy/engine/_processors_cy.py#L16-L24 is more related to #1981

What they're really looking for is the ability to work uncompiled and in environments without Cython (where import cython will fail completely)

@da-woods
Copy link
Contributor

da-woods commented Apr 6, 2024

Looking at the "Falconry" issue I think they're trying to do the same thing and essentially provide their own copy of "Shadow.py". I can see why they're doing it, but I still think the right solution is to distribute "Shadow.py" as a lightweight standalone package that people are happy to have as a runtime requirement rather than to try to follow imports through Python modules.

@scoder
Copy link
Contributor

scoder commented Apr 6, 2024

I agree that we should rather do #1981 than tracking arbitrary (runtime) imports across modules, including modules that are not even compiled, that might not be available at build time, or that happen to have the word cython in them.

@matusvalo
Copy link
Contributor Author

Now when I am looking at it again, I agree with @da-woods and @scoder. I think closing #1981 will eventually close this issue.

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

No branches or pull requests

3 participants