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
2 changes: 2 additions & 0 deletions .pylint.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ disable=
too-many-nested-blocks,
protected-access,
unspecified-encoding,
deprecated-class,
# Disabling these helps to write more expressive tests:
expression-not-assigned,
blacklisted-name,
Expand All @@ -37,6 +38,7 @@ disable=
cyclic-import,
comparison-with-callable,
unsupported-binary-operation,
invalid-field-call,

init-import=yes

Expand Down
6 changes: 2 additions & 4 deletions datafiles/converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def map_type(cls, *, name: str = "", item_cls: Optional[type] = None):
except AttributeError as e: # Python 3.9 behavior
assert "__args__" in str(e), f"Unhandled error: {e}"
raise TypeError("Type is required with 'List' annotation") from None
else:
converter = List.of_type(converter)
converter = List.of_type(converter)

elif cls.__origin__ == set:
try:
Expand All @@ -90,8 +89,7 @@ def map_type(cls, *, name: str = "", item_cls: Optional[type] = None):
except AttributeError as e: # Python 3.9 behavior
assert "__args__" in str(e), f"Unhandled error: {e}"
raise TypeError("Type is required with 'Set' annotation") from None
else:
converter = Set.of_type(converter)
converter = Set.of_type(converter)

elif isclass(cls.__origin__) and issubclass(cls.__origin__, Mapping):
if item_cls:
Expand Down
5 changes: 2 additions & 3 deletions datafiles/converters/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ def to_preserialization_data(cls, python_value, *, default_to_skip=None):
data = cls.TYPE(float(python_value))
except ValueError:
raise exc from None
else:
log.warn(f"Precision lost in conversion to int: {python_value}")
return data
log.warn(f"Precision lost in conversion to int: {python_value}")
return data


class String(Converter, str):
Expand Down
3 changes: 3 additions & 0 deletions datafiles/converters/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ def of_mappings(cls, dataclass, converters: Dict[str, type]):
@classmethod
def to_python_value(cls, deserialized_data, *, target_object=None):
if dataclasses.is_dataclass(deserialized_data):
assert not isinstance(
deserialized_data, type
), "Expected dataclass instance, not class"
data = dataclasses.asdict(deserialized_data)
elif isinstance(deserialized_data, dict):
data = deserialized_data.copy()
Expand Down
4 changes: 2 additions & 2 deletions datafiles/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def apply(instance, mapper):
setattr(cls, method_name, modified_method)

if is_dataclass(instance):
for attr_name in instance.datafile.attrs:
for attr_name in instance.datafile.attrs: # type: ignore
attr = getattr(instance, attr_name)
if isinstance(attr, list):
attr = types.List(attr)
Expand All @@ -64,7 +64,7 @@ def apply(instance, mapper):
elif isinstance(instance, list):
for item in instance:
if is_dataclass(item):
item.datafile = create_mapper(item, root=mapper)
item.datafile = create_mapper(item, root=mapper) # type: ignore
apply(item, mapper)

elif isinstance(instance, dict):
Expand Down
2 changes: 1 addition & 1 deletion datafiles/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
self._instance = instance
self._frozen = (
dataclasses.is_dataclass(self._instance)
and self._instance.__dataclass_params__.frozen
and self._instance.__dataclass_params__.frozen # type: ignore[union-attr]
)
self.attrs = attrs
self._pattern = pattern
Expand Down
10 changes: 5 additions & 5 deletions datafiles/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ def create_model(
if not hasattr(cls, "Meta") and infer is not None:
meta.datafile_infer = infer

cls.Meta = meta
cls.Meta = meta # type: ignore

# Patch manager

cls.objects = Manager(cls)
cls.objects = Manager(cls) # type: ignore

# Patch __init__

init = cls.__init__
init = cls.__init__ # type: ignore

def modified_init(self, *args, **kwargs):
with hooks.disabled():
init(self, *args, **kwargs)
Model.__post_init__(self)

cls.__init__ = modified_init
cls.__init__.__doc__ = init.__doc__
cls.__init__ = modified_init # type: ignore
cls.__init__.__doc__ = init.__doc__ # type: ignore

return cls
2 changes: 1 addition & 1 deletion datafiles/plugins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=no-name-in-module,unused-argument
# pylint: disable=no-name-in-module,unused-argument,no-value-for-parameter

from typing import Callable, Optional

Expand Down
261 changes: 78 additions & 183 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ black = "^24.3"
isort = "^5.10"

# Linters
mypy = "^1.3"
pylint = "~2.15"
mypy = "^1.18.1"
pylint = "~3.3.8"
pydocstyle = "*"

# Testing
Expand Down