Skip to content

Commit

Permalink
Add test for ambiguous associated item
Browse files Browse the repository at this point in the history
The `#[pyclass]` macro implements `IntoPyObject` for the annotated enum.
When the enum has any of `Error`, `Output` or `Target` as members, this
clashes with the associated types of `IntoPyObject`.

This also happens when deriving `IntoPyObject` directly.
  • Loading branch information
LilyFoote committed Nov 23, 2024
1 parent 06d2aff commit bd44c39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test_compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ fn test_compile_errors() {
t.compile_fail("tests/ui/duplicate_pymodule_submodule.rs");
#[cfg(all(not(Py_LIMITED_API), Py_3_11))]
t.compile_fail("tests/ui/invalid_base_class.rs");
t.pass("tests/ui/ambiguous_associated_items.rs");
}
25 changes: 25 additions & 0 deletions tests/ui/ambiguous_associated_items.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use pyo3::prelude::*;

#[pyclass(eq)]
#[derive(PartialEq)]
pub enum SimpleItems {
Error,
Output,
Target,
}

#[pyclass]
pub enum ComplexItems {
Error(PyObject),
Output(PyObject),
Target(PyObject),
}

#[derive(IntoPyObject)]
enum DeriveItems {
Error(PyObject),
Output(PyObject),
Target(PyObject),
}

fn main() {}

0 comments on commit bd44c39

Please sign in to comment.