@@ -75,14 +75,14 @@ impl PyErr {
75
75
///
76
76
/// Example:
77
77
/// ```ignore
78
- /// return Err(PyErr::new::<exceptions::TypeError , _>("Error message"));
78
+ /// return Err(PyErr::new::<exceptions::PyTypeError , _>("Error message"));
79
79
/// ```
80
80
///
81
81
/// In most cases, you can use a concrete exception's constructors instead:
82
82
/// the example is equivalent to
83
83
/// ```ignore
84
- /// return Err(exceptions::TypeError ::py_err("Error message"));
85
- /// return exceptions::TypeError ::into("Error message");
84
+ /// return Err(exceptions::PyTypeError ::py_err("Error message"));
85
+ /// return exceptions::PyTypeError ::into("Error message");
86
86
/// ```
87
87
pub fn new < T , V > ( value : V ) -> PyErr
88
88
where
@@ -105,7 +105,7 @@ impl PyErr {
105
105
/// Constructs a new error, with the usual lazy initialization of Python exceptions.
106
106
///
107
107
/// `exc` is the exception type; usually one of the standard exceptions
108
- /// like `exceptions::RuntimeError `.
108
+ /// like `exceptions::PyRuntimeError `.
109
109
/// `args` is the a tuple of arguments to pass to the exception constructor.
110
110
pub fn from_type < A > ( exc : & PyType , args : A ) -> PyErr
111
111
where
@@ -161,7 +161,7 @@ impl PyErr {
161
161
}
162
162
} else {
163
163
PyErr {
164
- ptype : exceptions:: TypeError :: type_object ( obj. py ( ) ) . into ( ) ,
164
+ ptype : exceptions:: PyTypeError :: type_object ( obj. py ( ) ) . into ( ) ,
165
165
pvalue : PyErrValue :: ToObject ( Box :: new ( "exceptions must derive from BaseException" ) ) ,
166
166
ptraceback : None ,
167
167
}
@@ -257,7 +257,7 @@ impl PyErr {
257
257
} ;
258
258
259
259
let ptype = if ptype. is_null ( ) {
260
- <exceptions:: SystemError as PyTypeObject >:: type_object ( py) . into ( )
260
+ <exceptions:: PySystemError as PyTypeObject >:: type_object ( py) . into ( )
261
261
} else {
262
262
Py :: from_owned_ptr ( py, ptype)
263
263
} ;
@@ -344,7 +344,7 @@ impl PyErr {
344
344
///
345
345
/// This method takes `mut self` because the error might need
346
346
/// to be normalized in order to create the exception instance.
347
- pub fn instance ( mut self , py : Python ) -> & exceptions:: BaseException {
347
+ pub fn instance ( mut self , py : Python ) -> & exceptions:: PyBaseException {
348
348
self . normalize ( py) ;
349
349
match self . pvalue {
350
350
PyErrValue :: Value ( ref instance) => {
@@ -439,7 +439,7 @@ impl FromPy<PyErr> for PyObject {
439
439
}
440
440
}
441
441
442
- impl FromPy < PyErr > for Py < exceptions:: BaseException > {
442
+ impl FromPy < PyErr > for Py < exceptions:: PyBaseException > {
443
443
fn from_py ( other : PyErr , py : Python ) -> Self {
444
444
other. instance ( py) . into ( )
445
445
}
@@ -462,7 +462,7 @@ impl<'a> IntoPy<PyObject> for &'a PyErr {
462
462
/// Convert `PyDowncastError` to Python `TypeError`.
463
463
impl std:: convert:: From < PyDowncastError > for PyErr {
464
464
fn from ( _err : PyDowncastError ) -> PyErr {
465
- exceptions:: TypeError :: py_err ( ( ) )
465
+ exceptions:: PyTypeError :: py_err ( ( ) )
466
466
}
467
467
}
468
468
@@ -515,28 +515,30 @@ impl std::convert::From<io::Error> for PyErr {
515
515
}
516
516
match err. kind ( ) {
517
517
io:: ErrorKind :: BrokenPipe => {
518
- PyErr :: from_value :: < exceptions:: BrokenPipeError > ( err_value ! ( ) )
518
+ PyErr :: from_value :: < exceptions:: PyBrokenPipeError > ( err_value ! ( ) )
519
519
}
520
520
io:: ErrorKind :: ConnectionRefused => {
521
- PyErr :: from_value :: < exceptions:: ConnectionRefusedError > ( err_value ! ( ) )
521
+ PyErr :: from_value :: < exceptions:: PyConnectionRefusedError > ( err_value ! ( ) )
522
522
}
523
523
io:: ErrorKind :: ConnectionAborted => {
524
- PyErr :: from_value :: < exceptions:: ConnectionAbortedError > ( err_value ! ( ) )
524
+ PyErr :: from_value :: < exceptions:: PyConnectionAbortedError > ( err_value ! ( ) )
525
525
}
526
526
io:: ErrorKind :: ConnectionReset => {
527
- PyErr :: from_value :: < exceptions:: ConnectionResetError > ( err_value ! ( ) )
527
+ PyErr :: from_value :: < exceptions:: PyConnectionResetError > ( err_value ! ( ) )
528
528
}
529
529
io:: ErrorKind :: Interrupted => {
530
- PyErr :: from_value :: < exceptions:: InterruptedError > ( err_value ! ( ) )
530
+ PyErr :: from_value :: < exceptions:: PyInterruptedError > ( err_value ! ( ) )
531
531
}
532
532
io:: ErrorKind :: NotFound => {
533
- PyErr :: from_value :: < exceptions:: FileNotFoundError > ( err_value ! ( ) )
533
+ PyErr :: from_value :: < exceptions:: PyFileNotFoundError > ( err_value ! ( ) )
534
534
}
535
535
io:: ErrorKind :: WouldBlock => {
536
- PyErr :: from_value :: < exceptions:: BlockingIOError > ( err_value ! ( ) )
536
+ PyErr :: from_value :: < exceptions:: PyBlockingIOError > ( err_value ! ( ) )
537
537
}
538
- io:: ErrorKind :: TimedOut => PyErr :: from_value :: < exceptions:: TimeoutError > ( err_value ! ( ) ) ,
539
- _ => PyErr :: from_value :: < exceptions:: OSError > ( err_value ! ( ) ) ,
538
+ io:: ErrorKind :: TimedOut => {
539
+ PyErr :: from_value :: < exceptions:: PyTimeoutError > ( err_value ! ( ) )
540
+ }
541
+ _ => PyErr :: from_value :: < exceptions:: PyOSError > ( err_value ! ( ) ) ,
540
542
}
541
543
}
542
544
}
@@ -549,7 +551,7 @@ impl PyErrArguments for io::Error {
549
551
550
552
impl < W : ' static + Send + std:: fmt:: Debug > std:: convert:: From < std:: io:: IntoInnerError < W > > for PyErr {
551
553
fn from ( err : std:: io:: IntoInnerError < W > ) -> PyErr {
552
- PyErr :: from_value :: < exceptions:: OSError > ( PyErrValue :: from_err_args ( err) )
554
+ PyErr :: from_value :: < exceptions:: PyOSError > ( PyErrValue :: from_err_args ( err) )
553
555
}
554
556
}
555
557
@@ -567,22 +569,28 @@ impl PyErrArguments for std::convert::Infallible {
567
569
568
570
impl std:: convert:: From < std:: convert:: Infallible > for PyErr {
569
571
fn from ( _: std:: convert:: Infallible ) -> PyErr {
570
- PyErr :: new :: < exceptions:: ValueError , _ > ( "Infalliable!" )
572
+ PyErr :: new :: < exceptions:: PyValueError , _ > ( "Infalliable!" )
571
573
}
572
574
}
573
575
574
- impl_to_pyerr ! ( std:: array:: TryFromSliceError , exceptions:: ValueError ) ;
575
- impl_to_pyerr ! ( std:: num:: ParseIntError , exceptions:: ValueError ) ;
576
- impl_to_pyerr ! ( std:: num:: ParseFloatError , exceptions:: ValueError ) ;
577
- impl_to_pyerr ! ( std:: num:: TryFromIntError , exceptions:: ValueError ) ;
578
- impl_to_pyerr ! ( std:: str :: ParseBoolError , exceptions:: ValueError ) ;
579
- impl_to_pyerr ! ( std:: ffi:: IntoStringError , exceptions:: UnicodeDecodeError ) ;
580
- impl_to_pyerr ! ( std:: ffi:: NulError , exceptions:: ValueError ) ;
581
- impl_to_pyerr ! ( std:: str :: Utf8Error , exceptions:: UnicodeDecodeError ) ;
582
- impl_to_pyerr ! ( std:: string:: FromUtf8Error , exceptions:: UnicodeDecodeError ) ;
583
- impl_to_pyerr ! ( std:: string:: FromUtf16Error , exceptions:: UnicodeDecodeError ) ;
584
- impl_to_pyerr ! ( std:: char :: DecodeUtf16Error , exceptions:: UnicodeDecodeError ) ;
585
- impl_to_pyerr ! ( std:: net:: AddrParseError , exceptions:: ValueError ) ;
576
+ impl_to_pyerr ! ( std:: array:: TryFromSliceError , exceptions:: PyValueError ) ;
577
+ impl_to_pyerr ! ( std:: num:: ParseIntError , exceptions:: PyValueError ) ;
578
+ impl_to_pyerr ! ( std:: num:: ParseFloatError , exceptions:: PyValueError ) ;
579
+ impl_to_pyerr ! ( std:: num:: TryFromIntError , exceptions:: PyValueError ) ;
580
+ impl_to_pyerr ! ( std:: str :: ParseBoolError , exceptions:: PyValueError ) ;
581
+ impl_to_pyerr ! ( std:: ffi:: IntoStringError , exceptions:: PyUnicodeDecodeError ) ;
582
+ impl_to_pyerr ! ( std:: ffi:: NulError , exceptions:: PyValueError ) ;
583
+ impl_to_pyerr ! ( std:: str :: Utf8Error , exceptions:: PyUnicodeDecodeError ) ;
584
+ impl_to_pyerr ! ( std:: string:: FromUtf8Error , exceptions:: PyUnicodeDecodeError ) ;
585
+ impl_to_pyerr ! (
586
+ std:: string:: FromUtf16Error ,
587
+ exceptions:: PyUnicodeDecodeError
588
+ ) ;
589
+ impl_to_pyerr ! (
590
+ std:: char :: DecodeUtf16Error ,
591
+ exceptions:: PyUnicodeDecodeError
592
+ ) ;
593
+ impl_to_pyerr ! ( std:: net:: AddrParseError , exceptions:: PyValueError ) ;
586
594
587
595
pub fn panic_after_error ( _py : Python ) -> ! {
588
596
unsafe {
@@ -611,7 +619,7 @@ mod tests {
611
619
fn set_typeerror ( ) {
612
620
let gil = Python :: acquire_gil ( ) ;
613
621
let py = gil. python ( ) ;
614
- let err: PyErr = exceptions:: TypeError :: py_err ( ( ) ) ;
622
+ let err: PyErr = exceptions:: PyTypeError :: py_err ( ( ) ) ;
615
623
err. restore ( py) ;
616
624
assert ! ( PyErr :: occurred( py) ) ;
617
625
drop ( PyErr :: fetch ( py) ) ;
0 commit comments