Skip to content

Commit

Permalink
Use @total_ordering and @Property
Browse files Browse the repository at this point in the history
  • Loading branch information
hssahota2 committed Mar 4, 2024
1 parent 985a8b5 commit f86de53
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions python/selfie-lib/selfie_lib/TypedPath.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
from functools import total_ordering


@total_ordering
class TypedPath:
def __init__(self, absolute_path: str):
self.absolute_path = absolute_path
self.name = self._get_name()
self.is_folder = self.absolute_path.endswith("/")

def _get_name(self) -> str:
@property
def name(self) -> str:
if self.absolute_path.endswith("/"):
path = self.absolute_path[:-1]
else:
path = self.absolute_path
last_slash = path.rfind("/")
return path[last_slash + 1 :]

@property
def is_folder(self) -> bool:
return self.absolute_path.endswith("/")

def assert_folder(self) -> None:
if not self.is_folder:
raise AssertionError(
Expand Down

0 comments on commit f86de53

Please sign in to comment.