-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2014 from b05902132/default_impl
Support default method implementation
- Loading branch information
Showing
5 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use pyo3::prelude::*; | ||
|
||
mod common; | ||
|
||
// Test default generated __repr__. | ||
#[pyclass] | ||
enum TestDefaultRepr { | ||
Var, | ||
} | ||
|
||
#[test] | ||
fn test_default_slot_exists() { | ||
Python::with_gil(|py| { | ||
let test_object = Py::new(py, TestDefaultRepr::Var).unwrap(); | ||
py_assert!( | ||
py, | ||
test_object, | ||
"repr(test_object) == 'TestDefaultRepr.Var'" | ||
); | ||
}) | ||
} | ||
|
||
#[pyclass] | ||
enum OverrideSlot { | ||
Var, | ||
} | ||
|
||
#[pymethods] | ||
impl OverrideSlot { | ||
fn __repr__(&self) -> &str { | ||
"overriden" | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_override_slot() { | ||
Python::with_gil(|py| { | ||
let test_object = Py::new(py, OverrideSlot::Var).unwrap(); | ||
py_assert!(py, test_object, "repr(test_object) == 'overriden'"); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters