Skip to content

Add support for #[pyclass(get(attr1, attr2, ...))] and #[pyclass(set(attr1, attr2, ...))]#5766

Open
davidhozic wants to merge 12 commits intoPyO3:mainfrom
davidhozic:feature/get-set-via-pyclass
Open

Add support for #[pyclass(get(attr1, attr2, ...))] and #[pyclass(set(attr1, attr2, ...))]#5766
davidhozic wants to merge 12 commits intoPyO3:mainfrom
davidhozic:feature/get-set-via-pyclass

Conversation

@davidhozic
Copy link

@davidhozic davidhozic commented Jan 30, 2026

Solves the problem in #5125, which mentions the problem of having helper attributes, such as #[pyo3(get)], while conditionally enabling pyclass using cfg_attr.

The problem is solved by allowing #[pyclass] to have options get and set, which accept a comma separated sequence of attribute names.

Progress:

  • Implement #[pyclass(get(attr1, attr2, ...))];
  • Implement #[pyclass(set(attr1, attr2, ...))];
  • Document changes;
  • Update documentation.

Example

#[cfg_attr(feature = "python-bindings", pyclass(module = "game", get(score, running), set(running)))]
pub struct GameManager {
    score: [u16; 2],
    running: bool
}

@davidhozic davidhozic changed the title Add support for pyo3(get(attr1, attr2, ...)) Add support for pyo3(get(attr1, attr2, ...)) and pyo3(set(attr1, attr2, ...)) Jan 30, 2026
@davidhozic davidhozic force-pushed the feature/get-set-via-pyclass branch from 7baface to 2ea93ce Compare January 30, 2026 23:36
@davidhozic davidhozic marked this pull request as ready for review January 31, 2026 00:46
@davidhozic davidhozic marked this pull request as draft January 31, 2026 01:09
@davidhozic davidhozic marked this pull request as ready for review January 31, 2026 01:31
@davidhozic davidhozic marked this pull request as draft January 31, 2026 10:50
@davidhozic davidhozic marked this pull request as ready for review January 31, 2026 13:15
@davidhozic davidhozic changed the title Add support for pyo3(get(attr1, attr2, ...)) and pyo3(set(attr1, attr2, ...)) Add support for #[pyclass(get(attr1, attr2, ...))] and #[pyclass(set(attr1, attr2, ...))] Jan 31, 2026
@davidhozic
Copy link
Author

Note: the tests in question seem to fail on the main branch as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant