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

Compile errors with 0.21.1 #4036

Closed
nickdrozd opened this issue Apr 2, 2024 · 6 comments · Fixed by #4054 or #4086
Closed

Compile errors with 0.21.1 #4036

nickdrozd opened this issue Apr 2, 2024 · 6 comments · Fixed by #4054 or #4086
Labels

Comments

@nickdrozd
Copy link

nickdrozd commented Apr 2, 2024

Bug Description

Updated to 0.21.1, now getting several of this error:

error[E0624]: associated constant `_PYO3_DEF` is private
  --> src/lib.rs:25:1
   |
25 | #[pymodule]
   | ^^^^^^^^^^^ private associated constant

This is using declarative modules. I assume it's related to #4009. Compiling with 0.21.0 works fine.

Steps to Reproduce

mod whatever;

use pyo3::prelude::*;

#[pymodule]
mod rust_stuff {
    #[pymodule_export]
    use crate::whatever::SomePyClass;
}

Backtrace

No response

Your operating system and version

Ubuntu

Your Python version (python --version)

3.12

Your Rust version (rustc --version)

rustc 1.79.0-nightly (5f2c7d2bf 2024-03-25)

Your PyO3 version

0.21.1

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

...

Additional Info

No response

@nickdrozd nickdrozd added the bug label Apr 2, 2024
@alex
Copy link
Contributor

alex commented Apr 2, 2024 via email

@nickdrozd
Copy link
Author

pub(crate) doesn't work, nor do other variations of pub.

The errors are coming both from #[pyclass] on pub struct and from create_exception!(mod_name, Whatever, PyException).

@davidhewitt
Copy link
Member

Yep this makes sense, in #4009 when I added the constants I didn't think about visibility. Should be a relatively easy fix, I will get to it by the end of the week if nobody else fancies taking a bite at this sooner.

@alecandido
Copy link

In case anyone arrives here, and it needs a workaround for v0.21.1 (current latest published release), wrapping the class in the other file (or non-pythonified module) in a further module makes it accessible.

use pyo3::prelude::*;

mod othermod {
    use pyo3::prelude::*;

    #[pymodule]
    pub mod wrapper {
        use pyo3::prelude::*;

        #[pyclass]
        pub struct Struct;
    }
}

#[pymodule]
mod myext {
    #[pymodule_export]
    use super::othermod::wrapper;
}

Ok, having this extra wrapper around is definitely less than ideal, but for me makes it acceptable to start using the declarative feature to experiment myself, waiting for a proper fix.

@nickdrozd
Copy link
Author

In 0.21.1 I was getting 7 compile errors, 3 from #[pyclass] and 4 from create_exception!.

In 0.21.2 the #[pyclass] errors are fixed, but I'm stil getting the 4 create_exception! errors.

Exceptions are created like this:

// rules.rs

create_exception!(rules, UnknownRule, PyException);

Then exported like this:

// lib.rs

mod rules;

#[pymodule]
mod rust_stuff {
    #[pymodule_export]
    use crate::rules::UnknownRule;
}

Error looks like:

error[E0624]: associated constant `_PYO3_DEF` is private
  --> src/lib.rs:31:1
   |
31 | #[pymodule]
   | ^^^^^^^^^^^ private associated constant
   |
  ::: src/rules.rs:12:1
   |
12 | create_exception!(rules, UnknownRule, PyException);
   | -------------------------------------------------- private associated constant defined here

If there is a better way to create exceptions, I would be happy to switch to that.

@Icxolu
Copy link
Contributor

Icxolu commented Apr 16, 2024

Thanks for reporting! I have opened #4086 which should fix it.

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