Skip to content

Commit

Permalink
SPath: Add append_to_stem (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
LightArrowsEXE authored Jun 3, 2024
1 parent bd2a89f commit 35c3125
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions stgpytools/types/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal, TypeAlias, Union

from ..functions import to_arr

__all__ = [
'FilePathType', 'FileDescriptor',
'FileOpener',
Expand Down Expand Up @@ -113,5 +115,10 @@ def write_lines(

return super().write_text('\n'.join(data), encoding, errors, newline)

def append_to_stem(self, suffixes: str | Iterable[str], sep: str = '_') -> SPath:
"""Append a suffix to the stem of the path"""

return self.with_stem(sep.join([self.stem, *to_arr(suffixes)])) # type:ignore[list-item]


SPathLike = Union[str, Path, SPath]

0 comments on commit 35c3125

Please sign in to comment.