MCPcopy Index your code
hub / github.com/RustPython/RustPython / is_file

Method is_file

crates/vm/src/stdlib/os.rs:712–734  ·  view source on GitHub ↗
(&self, follow_symlinks: FollowSymlinks, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

710
711 #[pymethod]
712 fn is_file(&self, follow_symlinks: FollowSymlinks, vm: &VirtualMachine) -> PyResult<bool> {
713 if let Ok(file_type) = &self.file_type
714 && (!follow_symlinks.0 || !file_type.is_symlink())
715 {
716 return Ok(file_type.is_file());
717 }
718 #[cfg(unix)]
719 if let Some(dt) = self.d_type {
720 let is_symlink = dt == libc::DT_LNK;
721 let need_stat = dt == libc::DT_UNKNOWN || (follow_symlinks.0 && is_symlink);
722 if !need_stat {
723 return Ok(dt == libc::DT_REG);
724 }
725 }
726 #[cfg(unix)]
727 return self.test_mode_via_stat(follow_symlinks.0, libc::S_IFREG as _, vm);
728 #[cfg(not(unix))]
729 match super::fs_metadata(&self.pathval, follow_symlinks.0) {
730 Ok(meta) => Ok(meta.is_file()),
731 Err(e) if e.kind() == io::ErrorKind::NotFound => Ok(false),
732 Err(e) => Err(e.into_pyexception(vm)),
733 }
734 }
735
736 #[pymethod]
737 fn is_symlink(&self, vm: &VirtualMachine) -> PyResult<bool> {

Callers 4

load_client_ca_listFunction · 0.45
load_from_dirMethod · 0.45
search_up_fileFunction · 0.45

Calls 6

fs_metadataFunction · 0.85
test_mode_via_statMethod · 0.80
ErrClass · 0.50
is_symlinkMethod · 0.45
kindMethod · 0.45
into_pyexceptionMethod · 0.45

Tested by

no test coverage detected