Skip to content

Commit

Permalink
fix: fix warnings due to marshmallow changes (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius authored Sep 1, 2022
1 parent e30d064 commit 6717fdf
Show file tree
Hide file tree
Showing 7 changed files with 276 additions and 256 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/auto-update-setup-py.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Update/generate setup.py
run: |
python -m pip install --upgrade pip
pip install dephell[full] mistune==0.8.4
pip install dephell[full] mistune==0.8.4 docutils==0.18.1
dephell deps convert --from pyproject.toml --to setup.py
- name: Fix setup.py format
run: |
Expand Down
11 changes: 9 additions & 2 deletions calamus/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,20 @@ class _JsonLDField(fields.Field):
"""

def __init__(self, field_name=None, *args, **kwargs):
super().__init__(*args, **kwargs)
if "default" in kwargs:
kwargs["load_default"] = kwargs.get("default")

filtered_kwargs = {
key: value
for key, value in kwargs.items()
if key not in ["reverse", "init_name", "add_value_types", "default"]
}
super().__init__(*args, **filtered_kwargs)
self.field_name = field_name

self.reverse = kwargs.get("reverse", False)
self.init_name = kwargs.get("init_name", None)
self.add_value_types = kwargs.get("add_value_types", False)
self.default = kwargs.get("default", None)

@property
def data_key(self):
Expand Down
12 changes: 6 additions & 6 deletions calamus/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ class User(metaclass=JsonLDAnnotation):
class Meta:
rdf_type = schema.Person
_id = fields.Id()
birth_date = fields.Date(schema.birthDate, default=dt.now)
name = fields.String(schema.name, default=lambda: "John")
birth_date = fields.Date(schema.birthDate, load_default=dt.now)
name = fields.String(schema.name, load_default=lambda: "John")
user = User()
Expand Down Expand Up @@ -573,11 +573,11 @@ def __new__(mcs, name, bases, namespace, **kwargs):
if isinstance(value, fields._JsonLDField):
attribute_dict[attr_name] = value

if hasattr(value, "default"):
if callable(value.default):
namespace[attr_name] = value.default()
if hasattr(value, "load_default"):
if callable(value.load_default):
namespace[attr_name] = value.load_default()
else:
namespace[attr_name] = value.default
namespace[attr_name] = value.load_default
else:
del namespace[attr_name]

Expand Down
Loading

0 comments on commit 6717fdf

Please sign in to comment.