Skip to content

Commit

Permalink
make fspath frozen
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekrubin committed Feb 26, 2025
1 parent 4caa06b commit bd756bb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 146 deletions.
42 changes: 21 additions & 21 deletions crates/ryo3-fspath/src/fspath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::path::{Path, PathBuf};
// separator
const MAIN_SEPARATOR: char = std::path::MAIN_SEPARATOR;

#[pyclass(name = "FsPath", module = "ryo3")]
#[pyclass(name = "FsPath", module = "ryo3", frozen)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PyFsPath {
pth: PathBuf,
Expand Down Expand Up @@ -408,26 +408,26 @@ impl PyFsPath {
// - PathBuf.push
// - PathBuf.set_extension
// - PathBuf.set_file_name

fn _push(mut slf: PyRefMut<'_, Self>, path: PathLike) -> PyRefMut<'_, PyFsPath> {
slf.pth.push(path);
slf
}

fn _pop(mut slf: PyRefMut<'_, Self>) -> PyRefMut<'_, PyFsPath> {
slf.pth.pop();
slf
}

fn _set_extension(mut slf: PyRefMut<'_, Self>, ext: String) -> PyRefMut<'_, PyFsPath> {
slf.pth.set_extension(ext);
slf
}

fn _set_file_name(mut slf: PyRefMut<'_, Self>, name: String) -> PyRefMut<'_, PyFsPath> {
slf.pth.set_file_name(name);
slf
}
// REMOVED FOR `frozen`
// fn _push(mut slf: PyRefMut<'_, Self>, path: PathLike) -> PyRefMut<'_, PyFsPath> {
// slf.pth.push(path);
// slf
// }
//
// fn _pop(mut slf: PyRefMut<'_, Self>) -> PyRefMut<'_, PyFsPath> {
// slf.pth.pop();
// slf
// }
//
// fn _set_extension(mut slf: PyRefMut<'_, Self>, ext: String) -> PyRefMut<'_, PyFsPath> {
// slf.pth.set_extension(ext);
// slf
// }
//
// fn _set_file_name(mut slf: PyRefMut<'_, Self>, name: String) -> PyRefMut<'_, PyFsPath> {
// slf.pth.set_file_name(name);
// slf
// }

// ========================================================================
// Methods from ::std::path::Path (Deref<Target=PathBuf>)
Expand Down
8 changes: 0 additions & 8 deletions python/ry/ryo3/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,6 @@ class FsPath:
@property
def suffixes(self) -> list[str]: ...

# =========================================================================
# std::path::PathBuf
# =========================================================================
def _pop(self) -> FsPath: ...
def _push(self, path: PathLike[str] | str) -> FsPath: ...
def _set_extension(self, ext: str) -> FsPath: ...
def _set_file_name(self, name: str) -> FsPath: ...

# =========================================================================
# std::path::PathBuf (deref -> std::path::Path)
# =========================================================================
Expand Down
117 changes: 0 additions & 117 deletions tests/fspath/test_fspath_rust_functions.py

This file was deleted.

0 comments on commit bd756bb

Please sign in to comment.