Skip to content
Discussion options

You must be logged in to vote

Right, I see. This idea of using #[pymethods] on std::ops::Add is interesting.

In principle we could support it (with limitations such as if you imported the trait under a different name like OpsAdd the macro would not recognise it). However, given the Add trait is generic (essentially overloadable), this would create a technical challenge which would likely make the PyO3 framework quite complicated. IMO for now there are higher priority items to tackle first.

The recommended way you can achieve this at the moment is to just define your Python __add__ as normal. You can make it handle multiple types using an enum input:

#[derive(FromPyObject)]
enum RasterOrF64 {
    Raster(Raster),
    F64(

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@jblindsay
Comment options

@jblindsay
Comment options

@jblindsay
Comment options

@davidhewitt
Comment options

@jblindsay
Comment options

Answer selected by jblindsay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants