Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
autosummary_generate = True # Turn on sphinx.ext.autosummary
autosummary_imported_members = True
# autodoc_inherit_docstrings = True
autodoc_member_order = "groupwise"
napoleon_include_init_with_doc = True
napoleon_numpy_docstring = True
viewcode_line_numbers = True
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["hatchling", "numpy", "cloudpickle"]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
Expand Down
28 changes: 23 additions & 5 deletions src/saveable_objects/_saveable_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def name(self) -> Optional[str]:
"""
return self._get_name(self._path)

def _save(self, path: str, write_mode: Literal["w", "wb", "a", "ab", "x", "xb"] = "wb"):
def _save(self,
path: str,
write_mode: Literal["w", "wb", "a", "ab", "x", "xb"] = "wb"):
"""Saves the object to `path` using `write_mode`.

Parameters
Expand Down Expand Up @@ -213,7 +215,11 @@ def update_save(self, path: Optional[str] = None) -> bool:
return True

@classmethod
def _load(cls, file: IO, new_path: Optional[str] = None, strict_typing: bool = True) -> "SaveableObject":
def _load(cls,
file: IO,
new_path: Optional[str] = None,
strict_typing: bool = True
) -> "SaveableObject":
"""Loads an instance from the `file`.

Parameters
Expand Down Expand Up @@ -251,7 +257,11 @@ def _load(cls, file: IO, new_path: Optional[str] = None, strict_typing: bool = T
instance.path = new_path
return instance
@classmethod
def load(cls, path: str, new_path: Optional[str] = None, strict_typing: bool = True) -> "SaveableObject":
def load(cls,
path: str,
new_path: Optional[str] = None,
strict_typing: bool = True
) -> "SaveableObject":
"""Loads a pickled instance.

Parameters
Expand Down Expand Up @@ -286,7 +296,11 @@ def load(cls, path: str, new_path: Optional[str] = None, strict_typing: bool = T
with open(path, "rb") as file:
return cls._load(file, new_path, strict_typing)
@classmethod
def tryload(cls, path: Optional[str], new_path: Optional[str] = None, strict_typing: bool = True) -> "SaveableObject" | Literal[False]:
def tryload(cls,
path: Optional[str],
new_path: Optional[str] = None,
strict_typing: bool = True
) -> "SaveableObject" | Literal[False]:
"""Attempts to :meth:`load` from the specified `path`. If the loading
fails then ``False`` is returned.

Expand Down Expand Up @@ -349,7 +363,11 @@ def loadif(cls, *args, **kwargs) -> Tuple["SaveableObject", bool]:
return instance, True
return cls(*args, **kwargs), False
@classmethod
def loadifparams(cls, *args, dependencies: dict = {}, **kwargs) -> Tuple["SaveableObject", bool]:
def loadifparams(cls,
*args,
dependencies: dict = {},
**kwargs
) -> Tuple["SaveableObject", bool]:
"""Attempts to :meth:`load` from a specified `path`. If the loading
fails or no `path` is specified or the parameters do not match the saved
parameters then a new instance of the object is generated with the
Expand Down
24 changes: 20 additions & 4 deletions src/saveable_objects/_saveable_object_3_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ def update_save(self, path: Optional[str] = None) -> bool:
return True

@classmethod
def _load(cls, file: IO, new_path: Optional[str] = None, strict_typing: bool = True) -> "SaveableObject":
def _load(cls,
file: IO,
new_path: Optional[str] = None,
strict_typing: bool = True
) -> "SaveableObject":
"""Loads an instance from the `file`.

Parameters
Expand Down Expand Up @@ -251,7 +255,11 @@ def _load(cls, file: IO, new_path: Optional[str] = None, strict_typing: bool = T
instance.path = new_path
return instance
@classmethod
def load(cls, path: str, new_path: Optional[str] = None, strict_typing: bool = True) -> "SaveableObject":
def load(cls,
path: str,
new_path: Optional[str] = None,
strict_typing: bool = True
) -> "SaveableObject":
"""Loads a pickled instance.

Parameters
Expand Down Expand Up @@ -286,7 +294,11 @@ def load(cls, path: str, new_path: Optional[str] = None, strict_typing: bool = T
with open(path, "rb") as file:
return cls._load(file, new_path, strict_typing)
@classmethod
def tryload(cls, path: Optional[str], new_path: Optional[str] = None, strict_typing: bool = True) -> Union["SaveableObject", bool]:
def tryload(cls,
path: Optional[str],
new_path: Optional[str] = None,
strict_typing: bool = True
) -> Union["SaveableObject", bool]:
"""Attempts to :meth:`load` from the specified `path`. If the loading
fails then ``False`` is returned.

Expand Down Expand Up @@ -349,7 +361,11 @@ def loadif(cls, *args, **kwargs) -> Tuple["SaveableObject", bool]:
return instance, True
return cls(*args, **kwargs), False
@classmethod
def loadifparams(cls, *args, dependencies: dict = {}, **kwargs) -> Tuple["SaveableObject", bool]:
def loadifparams(cls,
*args,
dependencies: dict = {},
**kwargs
) -> Tuple["SaveableObject", bool]:
"""Attempts to :meth:`load` from a specified `path`. If the loading
fails or no `path` is specified or the parameters do not match the saved
parameters then a new instance of the object is generated with the
Expand Down
8 changes: 4 additions & 4 deletions src/saveable_objects/checkpointing/_checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def failed(load_attempt: SaveableObject | bool | Tuple[SaveableObject, bool]) ->
:meth:`.load() <saveable_objects.SaveableObject.load>`,
:meth:`.tryload() <saveable_objects.SaveableObject.tryload>`,
:meth:`.loadif() <saveable_objects.SaveableObject.loadif>`, or
:meth:`.loadifparams() <saveable_objects.SaveableObject.loadifparams>` attempt
fails.
:meth:`.loadifparams() <saveable_objects.SaveableObject.loadifparams>`
attempt fails.

Parameters
----------
Expand Down Expand Up @@ -43,8 +43,8 @@ def succeeded(load_attempt: SaveableObject | bool | Tuple[SaveableObject, bool])
:meth:`.load() <saveable_objects.SaveableObject.load>`,
:meth:`.tryload() <saveable_objects.SaveableObject.tryload>`,
:meth:`.loadif() <saveable_objects.SaveableObject.loadif>`, or
:meth:`.loadifparams() <saveable_objects.SaveableObject.loadifparams>` attempt
succeeds.
:meth:`.loadifparams() <saveable_objects.SaveableObject.loadifparams>`
attempt succeeds.

Parameters
----------
Expand Down
8 changes: 4 additions & 4 deletions src/saveable_objects/checkpointing/_checkpointing_3_7.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def failed(load_attempt: Union[SaveableObject, bool, Tuple[SaveableObject, bool]
:meth:`.load() <saveable_objects.SaveableObject.load>`,
:meth:`.tryload() <saveable_objects.SaveableObject.tryload>`,
:meth:`.loadif() <saveable_objects.SaveableObject.loadif>`, or
:meth:`.loadifparams() <saveable_objects.SaveableObject.loadifparams>` attempt
fails.
:meth:`.loadifparams() <saveable_objects.SaveableObject.loadifparams>`
attempt fails.

Parameters
----------
Expand Down Expand Up @@ -43,8 +43,8 @@ def succeeded(load_attempt: Union[SaveableObject, bool, Tuple[SaveableObject, bo
:meth:`.load() <saveable_objects.SaveableObject.load>`,
:meth:`.tryload() <saveable_objects.SaveableObject.tryload>`,
:meth:`.loadif() <saveable_objects.SaveableObject.loadif>`, or
:meth:`.loadifparams() <saveable_objects.SaveableObject.loadifparams>` attempt
succeeds.
:meth:`.loadifparams() <saveable_objects.SaveableObject.loadifparams>`
attempt succeeds.

Parameters
----------
Expand Down
Loading