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

fix!: fully move all dependencies on pyo3 time types under our time feature + expose new abi3 feature for documentation #46

Merged
merged 4 commits into from
Jun 20, 2024

Conversation

antalsz
Copy link
Contributor

@antalsz antalsz commented Jun 10, 2024

I somehow missed to_python last time, despite the fact that I thought I'd tried building it.

@antalsz antalsz requested review from Shadow53 and kalzoo June 10, 2024 21:47
@antalsz antalsz self-assigned this Jun 10, 2024
@Shadow53
Copy link
Contributor

The check job uses cargo hack and checks with and without the time feature, so this seems good to me.

That said, the previous PR (#45) also passed this check, because there was nothing checking that any of those types actually implement the traits. Some simple "it compiles" checks would be useful to make sure this doesn't happen in the future. A macro would work here too, something like:

macro_rules! types_impl_trait {
    ($trait: ident, [$($ty: ty),+$(,)?]) => {
        paste::paste! {
            [< _impl_ $trait >]<T: $trait>() {}

            fn test_impls_$trait() {
                $(
                [< _impl_ $trait >]::<$ty>();
                )+
            }
        }
    }
}

types_impl_trait {
    ToPython, [
        Py<PyDate>,
        Py<PyDateTime>,
        // etc.
    ]
}

@antalsz
Copy link
Contributor Author

antalsz commented Jun 10, 2024

I think perhaps a better test would be to try to build this crate against a pyo3 with time disabled, which should reveal things immediately – (1) is there a good way to do that?, (2) does the explicit ToPython check there add anything in that case?

@antalsz antalsz changed the title fix: *actually* move all dependencies on pyo3 time types under our time feature fix: fully move all dependencies on pyo3 time types under our time feature + expose new abi3 feature for documentation Jun 11, 2024
@Shadow53
Copy link
Contributor

I think perhaps a better test would be to try to build this crate against a pyo3 with time disabled, which should reveal things immediately – (1) is there a good way to do that?, (2) does the explicit ToPython check there add anything in that case?

Yeah, so we've got basically a 2x2 grid of possible things (time is a stand-in for anything requiring not-abi3):

With time Without time
With abi3 Compile error (1) All good 👍🏻
Without abi3 Is ToPython etc. impl'd? (2) All good 👍🏻
  1. Error either from us or from pyo3/types not found
  2. The explicit ToPython (etc.) would check this and give a compile error if the trait is not implemented. Requires updating tests when adding types and/or traits.

@antalsz
Copy link
Contributor Author

antalsz commented Jun 13, 2024

Mm, I see. This fixes a different problem than the one that caused this PR (types being referenced that didn't exist), but still a worthy one. On the other hand, though, your comment "Requires updating tests when adding types and/or traits." makes me wonder if we'll actually get much of a benefit from adding those tests. It seems to me like it's just as easy to forget to add a test as it is to forget to add an implementation, and the tests won't catch you forgetting. Some more powerful "let's scrape all of these and test them" test would work here, but I'm not convinced we get a big win.

@antalsz
Copy link
Contributor Author

antalsz commented Jun 14, 2024

I thought this / #45 were just fixes, but rigetti/qcs-sdk-rust#475 shows that they can break things that were assuming the time types were in scope – I don't know that there's anything to do about the existing releases, but I'm upgrading this to fix!:

@antalsz antalsz changed the title fix: fully move all dependencies on pyo3 time types under our time feature + expose new abi3 feature for documentation fix!: fully move all dependencies on pyo3 time types under our time feature + expose new abi3 feature for documentation Jun 14, 2024
antalsz added a commit to rigetti/qcs-sdk-rust that referenced this pull request Jun 14, 2024
In rigetti/rigetti-pyo3#45 (and rigetti/rigetti-pyo3#46), I moved all
references to the Python time types under the "time" feature.  This
was a bugfix, but I didn't realize it was also a breaking change – any
library that relied on the time types implicitly being available would
break, just as this one did!  This adds the missing feature
dependency, and I've also upgraded rigetti/rigetti-pyo3#46 to be a
breaking change.

This commit also updates Cargo.lock to force the update to
rigetti-pyo3, meaning that builds will fail without the substantive
change.
antalsz added a commit to rigetti/qcs-sdk-rust that referenced this pull request Jun 14, 2024
In rigetti/rigetti-pyo3#45 (and rigetti/rigetti-pyo3#46), I moved all
references to the Python time types under the "time" feature.  This
was a bugfix, but I didn't realize it was also a breaking change – any
library that relied on the time types implicitly being available would
break, just as this one did!  This adds the missing feature
dependency, and I've also upgraded rigetti/rigetti-pyo3#46 to be a
breaking change.

This commit also updates Cargo.lock to force the update to
rigetti-pyo3, meaning that builds will fail without the substantive
change.

Closes #475.
@Shadow53
Copy link
Contributor

It seems to me like it's just as easy to forget to add a test as it is to forget to add an implementation, and the tests won't catch you forgetting. Some more powerful "let's scrape all of these and test them" test would work here, but I'm not convinced we get a big win.

Valid. I do not think that should block this being merged.

@antalsz antalsz merged commit 775df9d into main Jun 20, 2024
7 checks passed
@antalsz antalsz deleted the to_python-time-dependency branch June 20, 2024 19:02
antalsz added a commit that referenced this pull request Jun 20, 2024
…eature + expose new abi3 feature for documentation

This commit is so Knope will pick up 775df9d,
"Merge pull request #46 from rigetti/to_python-time-dependency".
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.

2 participants