Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.

Commit b396c1d

Browse files
authored
Merge pull request #64 from SVilgelm/autoformat
Autoformat
2 parents adb2f9b + 64bf902 commit b396c1d

File tree

3 files changed

+65
-75
lines changed

3 files changed

+65
-75
lines changed

marshmallow_objects/models.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@ def __new__(mcs, name, parents, dct):
5959
for parent in parents:
6060
if issubclass(parent, Model):
6161
parent_schemas.append(parent.__schema_class__)
62-
parent_schemas = (
63-
parent_schemas
64-
or [cls.__schema_class__ or marshmallow.Schema]
65-
)
66-
schema_class = type(
67-
name + 'Schema', tuple(parent_schemas), schema_fields)
62+
parent_schemas = (parent_schemas
63+
or [cls.__schema_class__ or marshmallow.Schema])
64+
schema_class = type(name + 'Schema', tuple(parent_schemas),
65+
schema_fields)
6866
cls.__schema_class__ = schema_class
6967

7068
return cls
@@ -102,13 +100,14 @@ def _deserialize(self, value, attr, data, **kwargs):
102100

103101
def with_metaclass(meta, *bases):
104102
"""Create a base class with a metaclass."""
103+
105104
# This requires a bit of explanation: the basic idea is to make a dummy
106105
# metaclass for one level of class instantiation that replaces itself with
107106
# the actual metaclass.
108107
class metaclass(meta): # noqa
109-
110108
def __new__(cls, name, this_bases, d):
111109
return meta(name, bases, d)
110+
112111
return type.__new__(metaclass, 'temporary_class', (), {})
113112

114113

@@ -197,8 +196,11 @@ def load_json(cls,
197196
*args,
198197
**kwargs):
199198
schema = cls.__get_schema_class__(context=context)
200-
loaded = schema.loads(
201-
data, many=many, partial=partial, *args, **kwargs)
199+
loaded = schema.loads(data,
200+
many=many,
201+
partial=partial,
202+
*args,
203+
**kwargs)
202204
if MM2:
203205
return loaded[0]
204206
return loaded
@@ -314,5 +316,7 @@ def dump_many_yaml(data,
314316
*args,
315317
**kwargs):
316318
ret = dump_many(data, context)
317-
return yaml.dump(
318-
ret, default_flow_style=default_flow_style, *args, **kwargs)
319+
return yaml.dump(ret,
320+
default_flow_style=default_flow_style,
321+
*args,
322+
**kwargs)

tests/test_models.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,14 @@ def test_schema_name(self):
8484

8585
def test_schema_class(self):
8686
assert issubclass(A.__schema_class__, marshmallow.Schema)
87-
assert issubclass(
88-
MultiInheritance.__schema_class__, marshmallow.Schema)
87+
assert issubclass(MultiInheritance.__schema_class__,
88+
marshmallow.Schema)
8989

9090
def test_model_class(self):
9191
assert issubclass(A.__schema_class__.__model_class__,
9292
marshmallow.Model)
93-
assert issubclass(
94-
MultiInheritance.__schema_class__.__model_class__,
95-
marshmallow.Model)
93+
assert issubclass(MultiInheritance.__schema_class__.__model_class__,
94+
marshmallow.Model)
9695

9796
def test_tag_processor(self):
9897
assert hasattr(A.__schema_class__, 'set_tag_field')
@@ -103,24 +102,21 @@ def test_meta(self):
103102
self.assertEqual(id(A.Meta), id(A.__schema_class__.Meta))
104103
assert not hasattr(B, 'Meta')
105104
assert hasattr(B.__schema_class__, 'Meta')
106-
self.assertEqual(
107-
id(MultiInheritance.Meta),
108-
id(MultiInheritance.__schema_class__.Meta))
105+
self.assertEqual(id(MultiInheritance.Meta),
106+
id(MultiInheritance.__schema_class__.Meta))
109107
assert hasattr(MultiInheritance.__schema_class__, 'Meta')
110108

111109
def test_on_bind_filed(self):
112-
self.assertEqual(
113-
id(A.on_bind_field), id(A.__schema_class__.on_bind_field))
114-
self.assertEqual(
115-
id(MultiInheritance.on_bind_field),
116-
id(MultiInheritance.__schema_class__.on_bind_field))
110+
self.assertEqual(id(A.on_bind_field),
111+
id(A.__schema_class__.on_bind_field))
112+
self.assertEqual(id(MultiInheritance.on_bind_field),
113+
id(MultiInheritance.__schema_class__.on_bind_field))
117114

118115
def test_handle_error(self):
119-
self.assertEqual(
120-
id(A.handle_error), id(A.__schema_class__.handle_error))
121-
self.assertEqual(
122-
id(MultiInheritance.handle_error),
123-
id(MultiInheritance.__schema_class__.handle_error))
116+
self.assertEqual(id(A.handle_error),
117+
id(A.__schema_class__.handle_error))
118+
self.assertEqual(id(MultiInheritance.handle_error),
119+
id(MultiInheritance.__schema_class__.handle_error))
124120

125121

126122
class TestModel(unittest.TestCase):
@@ -371,12 +367,11 @@ def test_load_many_as_one(self):
371367
self.assertRaises(marshmallow.ValidationError, B.load, self.data)
372368

373369
def test_load_many_partial(self):
374-
self.assertRaises(
375-
marshmallow.ValidationError,
376-
B.load,
377-
data=[{}, {}],
378-
many=True,
379-
partial=False)
370+
self.assertRaises(marshmallow.ValidationError,
371+
B.load,
372+
data=[{}, {}],
373+
many=True,
374+
partial=False)
380375
bb = B.load([{}, {}], many=True, partial=True)
381376
self.assertEqual(2, len(bb))
382377
for b in bb:
@@ -406,8 +401,9 @@ def test_dump_different_classes(self):
406401
self.assertEqual([self.data, adata], ddata)
407402

408403
def test_dump_fake(self):
409-
self.assertRaises(
410-
marshmallow.ValidationError, marshmallow.dump_many, data='fake')
404+
self.assertRaises(marshmallow.ValidationError,
405+
marshmallow.dump_many,
406+
data='fake')
411407

412408
def test_dump_context(self):
413409
context = {'value': 'bar'}

tools/bump_version

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import subprocess
55

66

77
def exec_cmd(cmd, input=None):
8-
p = subprocess.Popen(
9-
cmd,
10-
stdout=subprocess.PIPE,
11-
stdin=(subprocess.PIPE if input else None))
8+
p = subprocess.Popen(cmd,
9+
stdout=subprocess.PIPE,
10+
stdin=(subprocess.PIPE if input else None))
1211
stdout, _ = p.communicate(input and input.encode())
1312

1413
return str(stdout, 'utf-8')
@@ -17,27 +16,22 @@ def exec_cmd(cmd, input=None):
1716
@contextlib.contextmanager
1817
def disable_show_signature():
1918
local_flag = exec_cmd(
20-
["git", "config", "--local", "--get", "log.showSignature"]
21-
).strip()
22-
exec_cmd(
23-
["git", "config", "--local", "log.showSignature",
24-
"false"]
25-
)
19+
["git", "config", "--local", "--get", "log.showSignature"]).strip()
20+
exec_cmd(["git", "config", "--local", "log.showSignature", "false"])
2621
yield
2722
if local_flag:
28-
exec_cmd(
29-
["git", "config", "--local", "log.showSignature", local_flag]
30-
)
23+
exec_cmd(["git", "config", "--local", "log.showSignature", local_flag])
3124
else:
32-
exec_cmd(
33-
["git", "config", "--local", "--unset", "log.showSignature"]
34-
)
25+
exec_cmd(["git", "config", "--local", "--unset", "log.showSignature"])
3526

3627

3728
def get_diff(tag):
38-
return [l for l in exec_cmd([
39-
"git", "log", "--pretty=%h %s", "--no-merges", "{}..HEAD".format(tag)
40-
]).splitlines() if not l.startswith("gpg")]
29+
return [
30+
l for l in exec_cmd([
31+
"git", "log", "--pretty=%h %s", "--no-merges", "{}..HEAD".format(
32+
tag)
33+
]).splitlines() if not l.startswith("gpg")
34+
]
4135

4236

4337
def get_last_tag():
@@ -61,15 +55,14 @@ def get_info(version):
6155
new_tag = version or str_tag(inc_tag(last_tag))
6256

6357
subject = "Version {}".format(new_tag)
64-
changes = '\n'.join(
65-
'* {}'.format(line) for line in get_diff(str_tag(last_tag)))
58+
changes = '\n'.join('* {}'.format(line)
59+
for line in get_diff(str_tag(last_tag)))
6660

6761
annotation = """{subject}
6862
{sep}
6963
7064
{changes}
71-
""".format(
72-
subject=subject, sep='-' * len(subject), changes=changes)
65+
""".format(subject=subject, sep='-' * len(subject), changes=changes)
7366
return new_tag, annotation
7467

7568

@@ -131,21 +124,18 @@ if __name__ == '__main__':
131124
import argparse
132125

133126
parser = argparse.ArgumentParser()
134-
parser.add_argument(
135-
'version',
136-
nargs='?',
137-
help="specify version, otherwise the current version "
138-
"will be incremented by 1")
139-
parser.add_argument(
140-
'-s',
141-
'--sign',
142-
action='store_true',
143-
help="sign a tag and commits")
144-
parser.add_argument(
145-
'-r',
146-
'--dry-run',
147-
action='store_true',
148-
help="print tag's number and annotation")
127+
parser.add_argument('version',
128+
nargs='?',
129+
help="specify version, otherwise the current version "
130+
"will be incremented by 1")
131+
parser.add_argument('-s',
132+
'--sign',
133+
action='store_true',
134+
help="sign a tag and commits")
135+
parser.add_argument('-r',
136+
'--dry-run',
137+
action='store_true',
138+
help="print tag's number and annotation")
149139

150140
args = parser.parse_args()
151141

0 commit comments

Comments
 (0)