From fc3ab84bfac95836a93fa7d0fb85b407285908a2 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 26 Jul 2017 14:56:08 -0700 Subject: [PATCH] better constrain for PyNativeException::new --- guide/src/exception.md | 6 +++--- src/objects/exc_impl.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/guide/src/exception.md b/guide/src/exception.md index 77892e29..c5f2ac27 100644 --- a/guide/src/exception.md +++ b/guide/src/exception.md @@ -144,9 +144,9 @@ The code snippet above will raise `OSError` in Python if `TcpListener::bind()` r types so `try!` macro or `?` operator can be used. ```rust -use pyo3::{PyResult, ToPyErr}; +use pyo3::*; -fn parse_int(py: Python, s: String) -> PyResult { +fn parse_int(s: String) -> PyResult { Ok(s.parse::()?) } ``` @@ -161,7 +161,7 @@ It is possible to use exception defined in python code as native rust types. for that exception. ```rust -use pyo3::{PyErr, PyResult, ToPyErr, exc}; +use pyo3::{PyErr, PyResult, exc}; import_exception!(asyncio, CancelledError) diff --git a/src/objects/exc_impl.rs b/src/objects/exc_impl.rs index b83fdb80..8c3a86d3 100644 --- a/src/objects/exc_impl.rs +++ b/src/objects/exc_impl.rs @@ -81,8 +81,8 @@ pub trait PyNativeException { /// Name of exception const NAME: &'static str; - fn new(args: T) -> PyErr { - PyErr::new::(args) + fn new(args: T) -> PyErr where Self: PyTypeObject + Sized { + PyErr::new::(args) } fn type_object_ptr() -> *mut ffi::PyTypeObject {