Skip to content

Commit c9fb7aa

Browse files
author
Jace Browning
committed
Remove unused code
1 parent a51507b commit c9fb7aa

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

datafiles/converters/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ def map_type(cls, *, name: str = '', item_cls: Optional[type] = None):
5757
try:
5858
converter = map_type(item_cls or cls.__args__[0])
5959
except TypeError as e:
60-
if '~T' in str(e):
61-
e = TypeError(f"Type is required with 'List' annotation")
62-
raise e from None
60+
assert '~T' in str(e), f'Unhandled error: ' + str(e)
61+
raise TypeError("Type is required with 'List' annotation") from None
6362
else:
6463
converter = List.subclass(converter)
6564

datafiles/formats.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from pathlib import Path
88
from typing import IO, Any, Dict, List
99

10-
import log
11-
1210
from . import settings, types
1311

1412

@@ -86,11 +84,7 @@ def extensions(cls):
8684
def deserialize(cls, file_object):
8785
from ruamel import yaml
8886

89-
try:
90-
return yaml.round_trip_load(file_object, preserve_quotes=True) or {}
91-
except NotImplementedError as e:
92-
log.error(str(e))
93-
return {}
87+
return yaml.round_trip_load(file_object, preserve_quotes=True) or {}
9488

9589
@classmethod
9690
def serialize(cls, data):
@@ -151,19 +145,21 @@ def increase_indent(self, flow=False, indentless=False):
151145
return text
152146

153147

154-
def deserialize(path: Path, extension: str) -> Dict:
155-
formatter = _get_formatter(extension)
148+
def deserialize(path: Path, extension: str, *, formatter=None) -> Dict:
149+
if formatter is None:
150+
formatter = _get_formatter(extension)
156151
with path.open('r') as file_object:
157152
return formatter.deserialize(file_object)
158153

159154

160-
def serialize(data: Dict, extension: str = '.yml') -> str:
161-
formatter = _get_formatter(extension)
155+
def serialize(data: Dict, extension: str = '.yml', *, formatter=None) -> str:
156+
if formatter is None:
157+
formatter = _get_formatter(extension)
162158
return formatter.serialize(data)
163159

164160

165161
def _get_formatter(extension: str):
166-
if settings.YAML_LIBRARY == 'PyYAML':
162+
if settings.YAML_LIBRARY == 'PyYAML': # pragma: no cover
167163
register('.yml', PyYAML)
168164

169165
with suppress(KeyError):

datafiles/tests/test_formats.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def data():
1313

1414
def describe_ruamel_yaml():
1515
def it_indents_blocks_by_default(expect, data):
16-
text = formats.RuamelYAML.serialize(data)
16+
text = formats.serialize(data, '.yaml')
1717
expect(text) == dedent(
1818
"""
1919
key: value
@@ -26,7 +26,7 @@ def it_indents_blocks_by_default(expect, data):
2626

2727
def it_can_render_lists_inline(expect, data, monkeypatch):
2828
monkeypatch.setattr(settings, 'INDENT_YAML_BLOCKS', False)
29-
text = formats.RuamelYAML.serialize(data)
29+
text = formats.serialize(data, '.yaml')
3030
expect(text) == dedent(
3131
"""
3232
key: value
@@ -39,7 +39,7 @@ def it_can_render_lists_inline(expect, data, monkeypatch):
3939

4040
def describe_pyyaml():
4141
def it_indents_blocks_by_default(expect, data):
42-
text = formats.PyYAML.serialize(data)
42+
text = formats.serialize(data, '.yaml', formatter=formats.PyYAML)
4343
expect(text) == dedent(
4444
"""
4545
key: value
@@ -52,7 +52,7 @@ def it_indents_blocks_by_default(expect, data):
5252

5353
def it_can_render_lists_inline(expect, data, monkeypatch):
5454
monkeypatch.setattr(settings, 'INDENT_YAML_BLOCKS', False)
55-
text = formats.PyYAML.serialize(data)
55+
text = formats.serialize(data, '.yaml', formatter=formats.PyYAML)
5656
expect(text) == dedent(
5757
"""
5858
key: value
@@ -71,18 +71,26 @@ def path(tmp_path):
7171
path.write_text("")
7272
return path
7373

74-
def with_empty_yaml_file(expect, path):
75-
data = formats.deserialize(path, '.yaml')
76-
expect(data) == {}
74+
def describe_ruamel_yaml():
75+
def with_empty_file(expect, path):
76+
data = formats.deserialize(path, '.yaml')
77+
expect(data) == {}
78+
79+
def describe_pyyaml():
80+
def with_empty_file(expect, path):
81+
data = formats.deserialize(path, '.yaml', formatter=formats.PyYAML)
82+
expect(data) == {}
7783

78-
def with_empty_json_file(expect, path):
79-
path.write_text("{}")
80-
data = formats.deserialize(path, '.json')
81-
expect(data) == {}
84+
def describe_json():
85+
def with_empty_file(expect, path):
86+
path.write_text("{}")
87+
data = formats.deserialize(path, '.json')
88+
expect(data) == {}
8289

83-
def with_empty_toml_file(expect, path):
84-
data = formats.deserialize(path, '.toml')
85-
expect(data) == {}
90+
def describe_toml():
91+
def with_empty_file(expect, path):
92+
data = formats.deserialize(path, '.toml')
93+
expect(data) == {}
8694

8795
def with_unknown_extension(expect, path):
8896
with expect.raises(ValueError):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22

33
name = "datafiles"
4-
version = "0.9b3"
4+
version = "0.9b4"
55
description = "File-based ORM for dataclasses."
66

77
license = "MIT"

0 commit comments

Comments
 (0)