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

Defining pymethods in a different module silently fails #4281

Open
Rigidity opened this issue Jun 24, 2024 · 0 comments
Open

Defining pymethods in a different module silently fails #4281

Rigidity opened this issue Jun 24, 2024 · 0 comments
Labels

Comments

@Rigidity
Copy link

Rigidity commented Jun 24, 2024

Bug Description

Note that the below issue only seems to occur when:

  • The binding is defined in a different crate than the entrypoint
  • The multiple-pybindings feature is enabled

If you define a pyclass in one module, then pymethods in a different module, it fails to expose the bindings to Python without a compile time error. I did this to clean up imports, and would have expected it to not make a difference (similar to how you can impl a normal struct in a different module within the same crate). I tried re-exporting everything from the pybindings module, as well as making it public, to no avail.

Here is the original fix PR I had to make, if it helps
Chia-Network/chia_rs#583

Steps to Reproduce

Here is an example of this issue:
https://github.com/Rigidity/pyo3-repro

Clone the repo, then run

python3 -m venv venv
. ./venv/bin/activate
pip install maturin

maturin develop -m Cargo.toml
python main.py

Then remove multiple-pymethods from Cargo.toml and run:

maturin develop -m Cargo.toml
python main.py

It now works. You can also remove the submodule module, and put the pymethods in the same module as the Example struct, and it will also work.

Backtrace

Traceback (most recent call last):
  File "main.py", line 3, in <module>
    print(Example())
TypeError: No constructor defined

Your operating system and version

MacOS Sonoma 14.5

Your Python version (python --version)

Python 3.8.18

Your Rust version (rustc --version)

rustc 1.80.0-nightly (032af18af 2024-06-02)

Your PyO3 version

0.21.2

How did you install python? Did you use a virtualenv?

I use pyenv

Additional Info

No response

@Rigidity Rigidity added the bug label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant