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

Pyclass Hygiene Structs and Complex Enums #4358

Closed
Zyell opened this issue Jul 17, 2024 · 1 comment
Closed

Pyclass Hygiene Structs and Complex Enums #4358

Zyell opened this issue Jul 17, 2024 · 1 comment
Labels

Comments

@Zyell
Copy link
Contributor

Zyell commented Jul 17, 2024

Bug Description

While working on the str implementation for pyclass, I found that eq for pyclass for structs had a hygiene issue. I created a test in the pyclass hygiene tests to cover this scenario and it passes. I noticed that complex and tuple enums do not have any tests for hygiene, so I added them, but am struggling to get them to fully pass.

Steps to Reproduce

  1. Add the following test cases to src/tests/hygiene/pyclass.rs:
#[crate::pyclass(eq, ord)]
#[pyo3(crate = "crate")]
#[derive(PartialEq, PartialOrd)]
pub struct PointEqOrd {
    x: u32,
    y: u32,
    z: u32,
}

#[crate::pyclass(eq, ord)]
#[pyo3(crate = "crate")]
#[derive(PartialEq, PartialOrd)]
pub enum ComplexEnumEqOrd {
    Variant1 { a: u32, b: u32 },
    Variant2 { c: u32 },
}

#[crate::pyclass(eq, ord)]
#[pyo3(crate = "crate")]
#[derive(PartialEq, PartialOrd)]
pub enum TupleEnumEqOrd {
    Variant1(u32, u32),
    Variant2(u32),
}

Backtrace

Errors were of the type:

error: cannot find macro `unreachable` in this scope
  --> src/tests/hygiene/pyclass.rs:79:1
   |
79 | #[crate::pyclass()]
   | ^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the attribute macro `crate::pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
   |
1  + use core::unreachable;
   |
1  + use std::unreachable;
   |

error[E0423]: expected value, found enum `std::result::Result`
  --> src/tests/hygiene/pyclass.rs:79:1
   |
79 | #[crate::pyclass()]
   | ^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the attribute macro `crate::pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
help: the following enum variants are available
   |
79 | (std::result::Result::Err(/* fields */))
   |
79 | (std::result::Result::Ok(/* fields */))

I am now encountering the following errors for my enum test cases that I'm not quite sure how to resolve:

error[E0599]: no function or associated item named `from` found for struct `pyclass_init::PyClassInitializer` in the current scope
   --> src/tests/hygiene/pyclass.rs:87:1
    |
87  | #[crate::pyclass(eq, ord)]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `PyClassInitializer<_>`
    |
   ::: src/pyclass_init.rs:136:1
    |
136 | pub struct PyClassInitializer<T: PyClass>(PyClassInitializerImpl<T>);
    | ----------------------------------------- function or associated item `from` not found for this struct
    |
note: if you're trying to build a new `pyclass_init::PyClassInitializer<_>`, consider using `pyclass_init::PyClassInitializer::<T>::new` which returns `pyclass_init::PyClassInitializer<_>`
   --> src/pyclass_init.rs:150:5
    |
150 |     pub fn new(init: T, super_init: <T::BaseType as PyClassBaseType>::Initializer) -> Self {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: items from traits can only be used if the trait is in scope
    = note: this error originates in the attribute macro `crate::pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
help: trait `From` which provides `from` is implemented but not in scope; perhaps you want to import it
    |
1   + use std::convert::From;
    |
help: there is an associated function `try_from` with a similar name
    |
87  | try_from
    |

error[E0599]: no method named `clone` found for reference `&u32` in the current scope
   --> src/tests/hygiene/pyclass.rs:87:1
    |
87  | #[crate::pyclass(eq, ord)]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: items from traits can only be used if the trait is in scope
help: there is a method `clone_from` with a similar name, but with different arguments
   --> /var/home/zyell/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/clone.rs:169:5
    |
169 |     fn clone_from(&mut self, source: &Self) {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: this error originates in the attribute macro `crate::pyclass` (in Nightly builds, run with -Z macro-backtrace for more info)
help: trait `Clone` which provides `clone` is implemented but not in scope; perhaps you want to import it
    |
1   + use std::clone::Clone;
    |



### Your operating system and version

Bluefin fedora 40

### Your Python version (`python --version`)

3.12.4

### Your Rust version (`rustc --version`)

1.79.0

### Your PyO3 version

main

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

virtualenv

### Additional Info

_No response_
@Zyell
Copy link
Contributor Author

Zyell commented Jul 17, 2024

resolved in #4359

@Zyell Zyell closed this as completed Jul 17, 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