PyO3 / PyO3/pyo3

`#[pyo3(get)]` and `#[getter]` on same field silently collide

Open
#6,000 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

The following code compiles without issue. I would expect we should either fail to compile or report an error when initializing the type object. Compile error probably leads to better UX, as long as the compiler error is meaningful enough.

#[pyclass]
pub struct Object {
    #[pyo3(get)]
    x: u32,
}

#[pymethods]
impl Object {
    #[getter]
    fn x(&self) -> u32 {
        self.x
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided #[pyclass], #[pyo3(get)], and #[getter] reproducer and trace how the two attributes generate the type's accessors. The work is done when the collision is detected and produces a meaningful compile-time or type-initialization error, with coverage for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.