Skip to content

Question: function overriding doesn't seem to work in python #1917

Answered by davidhewitt
shi-yan asked this question in Questions
Discussion options

You must be logged in to vote

Hi, there's two problems with your snippet above:

  • You're ignoring the error when you call cls.call_method. The compiler is even warning you this:
    warning: unused `Result` that must be used 35/36: pyo3-scratch
    --> src/lib.rs:19:9
       |
    19 |         cls.call_method("override_test", (), None);
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: `#[warn(unused_must_use)]` on by default
       = note: this `Result` may be an `Err` variant, which should be handled
    
  • Your override in Python is not a classmethod.

If I add ? at the end of cls_call_method(...)?;, so that the error is correctly propagated, so the print_test function looks like this:

    #[classmethod]
    fn print_…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by davidhewitt
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
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 participants
Converted from issue

This discussion was converted from issue #1875 on October 13, 2021 20:51.