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

Add a License #1

Closed
sno2 opened this issue Oct 11, 2021 · 4 comments
Closed

Add a License #1

sno2 opened this issue Oct 11, 2021 · 4 comments

Comments

@sno2
Copy link

sno2 commented Oct 11, 2021

Hello, do you think you could add a license because I want to use your proc macro for inserting #[pyo3(get)] into all class fields? I also need to hide the attribute under a feature by default and the bug is a big blocker. Thanks

@mejrs
Copy link
Owner

mejrs commented Oct 11, 2021

I am willing to do that (I should have done it long ago), but I do not think you should use it.

It relies on #[cfg_eval] to expand eagerly:

While I personally use nightly features freely as this is a toy project and I don't mind it breaking on me, this is a pretty unstable feature. Certainly not something you should be using in production.

To resolve your issue now, you can also define some getters and gate those behind a cfg. Something like this:

#[cfg(feature = "pyo3")]
#[pymethods]
impl LocationConfig {
    #[getter]
    fn id(&self) -> PyResult<u32> {
        Ok(self.id)
    }

    #[getter]
    fn name(&self) -> PyResult<Option<String>> {
        Ok(self.name.clone())
    }

    // etc..
}

@mejrs
Copy link
Owner

mejrs commented Oct 11, 2021

Done.

@sno2
Copy link
Author

sno2 commented Oct 11, 2021

I am willing to do that (I should have done it long ago), but I do not think you should use it.

It relies on #[cfg_eval] to expand eagerly:

While I personally use nightly features freely as this is a toy project and I don't mind it breaking on me, this is a pretty unstable feature. Certainly not something you should be using in production.

To resolve your issue now, you can also define some getters and gate those behind a cfg. Something like this:

#[cfg(feature = "pyo3")]
#[pymethods]
impl LocationConfig {
    #[getter]
    fn id(&self) -> PyResult<u32> {
        Ok(self.id)
    }

    #[getter]
    fn name(&self) -> PyResult<Option<String>> {
        Ok(self.name.clone())
    }

    // etc..
}

Thanks for the feedback and adding the license, I hadn't realized that your solution still relied on nightly. I think I'll just still with dicts for my response data in Python for now and hope for #[pyclass(dataclass)] or something of sort.

@sno2 sno2 closed this as completed Oct 11, 2021
@mejrs
Copy link
Owner

mejrs commented Oct 11, 2021

Something like a #[pyclass(get_all)] and #[pyclass(set_all)] is something I'd like too.

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

No branches or pull requests

2 participants