Skip to content

Cannot use FromPyObject + IntoPyObject with #[pyo3(default)] #4989

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

Closed
bbstilson opened this issue Mar 17, 2025 · 2 comments
Closed

Cannot use FromPyObject + IntoPyObject with #[pyo3(default)] #4989

bbstilson opened this issue Mar 17, 2025 · 2 comments
Labels

Comments

@bbstilson
Copy link

bbstilson commented Mar 17, 2025

Bug Description

This #4643 PR introduced the #[pyo3(default)] attribute macro. Unfortunately, it doesn't work when both FromPyObject and IntoPyObject are derived for the same object.

Steps to Reproduce

Compiles fine:

#[derive(FromPyObject)]
struct Foo {
    #[pyo3(default)]
    x: Option<String>
}

This does not:

#[derive(FromPyObject, IntoPyObject)]
struct Foo {
    #[pyo3(default)]
    x: Option<String>
}

error: expected one of: `attribute`, `item`, `into_py_with`
   --> src/foo.rs:3:12
    |
122 |     #[pyo3(default)]
    |            ^^^^^^^

Backtrace

Your operating system and version

Ubuntu 22

Your Python version (python --version)

Python 3.10.12

Your Rust version (rustc --version)

rustc 1.85.0 (4d91de4e4 2025-02-17)

Your PyO3 version

0.24.0

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

venv

Additional Info

No response

@bbstilson bbstilson added the bug label Mar 17, 2025
@Icxolu
Copy link
Contributor

Icxolu commented Mar 17, 2025

See also #4884

@bbstilson
Copy link
Author

@Icxolu sorry I missed that one! I did a search for default and didn't find anything. Feel free to close this if this is just a subset of the problem captured in #4884

@davidhewitt davidhewitt closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2025
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

3 participants