Skip to content

Commit

Permalink
Only warn when using deprecated feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed May 22, 2021
1 parent 535e4c7 commit 4110466
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
11 changes: 11 additions & 0 deletions datafiles/hooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from contextlib import contextmanager, suppress
from dataclasses import is_dataclass
from functools import wraps
Expand Down Expand Up @@ -89,6 +90,11 @@ def wrapped(self, *args, **kwargs):
if mapper.auto_save:
log.debug("Saving automatically after load")
mapper.save(_log=False)
else:
warnings.warn(
"'auto_save' is deprecated, use 'manual' instead",
DeprecationWarning,
)

return method(self, *args, **kwargs)

Expand Down Expand Up @@ -122,6 +128,11 @@ def wrapped(self, *args, **kwargs):
if mapper.auto_load:
log.debug("Loading automatically after save")
mapper.load(_log=False)
else:
warnings.warn(
"'auto_load' is deprecated, use 'manual' instead",
DeprecationWarning,
)

return result

Expand Down
1 change: 0 additions & 1 deletion datafiles/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


if TYPE_CHECKING:
from .mapper import Mapper
from .model import Model


Expand Down
9 changes: 0 additions & 9 deletions datafiles/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dataclasses
import inspect
import os
import warnings
from pathlib import Path
from typing import Any, Dict, Optional

Expand Down Expand Up @@ -34,14 +33,6 @@ def __init__(
) -> None:
assert manual is not None
assert defaults is not None
if auto_load is not None:
warnings.warn(
"'auto_load' is deprecated, use 'manual' instead", DeprecationWarning
)
if auto_save is not None:
warnings.warn(
"'auto_save' is deprecated, use 'manual' instead", DeprecationWarning
)
self._instance = instance
self.attrs = attrs
self._pattern = pattern
Expand Down
7 changes: 0 additions & 7 deletions datafiles/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dataclasses
import warnings

import log
from classproperties import classproperty
Expand Down Expand Up @@ -74,14 +73,8 @@ def create_model(
if not hasattr(cls, 'Meta') and defaults is not None:
m.datafile_defaults = defaults
if not hasattr(cls, 'Meta') and auto_load is not None:
warnings.warn(
"'auto_load' is deprecated, use 'manual' instead", DeprecationWarning
)
m.datafile_auto_load = auto_load
if not hasattr(cls, 'Meta') and auto_save is not None:
warnings.warn(
"'auto_save' is deprecated, use 'manual' instead", DeprecationWarning
)
m.datafile_auto_save = auto_save
if not hasattr(cls, 'Meta') and infer is not None:
m.datafile_infer = infer
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]

name = "datafiles"
version = "0.14"
version = "0.14.post1"
description = "File-based ORM for dataclasses."

license = "MIT"
Expand Down

0 comments on commit 4110466

Please sign in to comment.