Skip to content

Commit d8d7c27

Browse files
committed
map io::ErrorKind::IsADirectory/NotADirectory to Python on 1.83+
1 parent 1183ea3 commit d8d7c27

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

newsfragments/4747.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Map `io::ErrorKind::IsADirectory`/`NotADirectory` to the corresponding Python exception on Rust 1.83+

pyo3-build-config/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ pub fn print_feature_cfgs() {
156156
if rustc_minor_version >= 79 {
157157
println!("cargo:rustc-cfg=diagnostic_namespace");
158158
}
159+
160+
if rustc_minor_version >= 83 {
161+
println!("cargo:rustc-cfg=io_error_more");
162+
}
159163
}
160164

161165
/// Registers `pyo3`s config names as reachable cfg expressions
@@ -180,6 +184,7 @@ pub fn print_expected_cfgs() {
180184
println!("cargo:rustc-check-cfg=cfg(diagnostic_namespace)");
181185
println!("cargo:rustc-check-cfg=cfg(c_str_lit)");
182186
println!("cargo:rustc-check-cfg=cfg(rustc_has_once_lock)");
187+
println!("cargo:rustc-check-cfg=cfg(io_error_more)");
183188

184189
// allow `Py_3_*` cfgs from the minimum supported version up to the
185190
// maximum minor version (+1 for development for the next)

src/err/impls.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ impl From<io::Error> for PyErr {
5454
io::ErrorKind::AlreadyExists => exceptions::PyFileExistsError::new_err(err),
5555
io::ErrorKind::WouldBlock => exceptions::PyBlockingIOError::new_err(err),
5656
io::ErrorKind::TimedOut => exceptions::PyTimeoutError::new_err(err),
57+
#[cfg(io_error_more)]
58+
io::ErrorKind::IsADirectory => exceptions::PyIsADirectoryError::new_err(err),
59+
#[cfg(io_error_more)]
60+
io::ErrorKind::NotADirectory => exceptions::PyNotADirectoryError::new_err(err),
5761
_ => exceptions::PyOSError::new_err(err),
5862
}
5963
}

0 commit comments

Comments
 (0)