Skip to content

Commit ee2de6d

Browse files
committed
More style fun.
1 parent e7d2975 commit ee2de6d

7 files changed

Lines changed: 34 additions & 31 deletions

File tree

jsonschema/_format.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def is_email(instance):
156156

157157
_ipv4_re = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
158158

159+
159160
@_checks_drafts(draft3="ip-address", draft4="ipv4")
160161
def is_ipv4(instance):
161162
if not isinstance(instance, str_types):
@@ -175,6 +176,7 @@ def is_ipv6(instance):
175176

176177
_host_name_re = re.compile(r"^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$")
177178

179+
178180
@_checks_drafts(draft3="host-name", draft4="hostname")
179181
def is_host_name(instance):
180182
if not isinstance(instance, str_types):
@@ -209,13 +211,13 @@ def is_uri(instance):
209211
pass
210212
else:
211213
@_checks_drafts("date-time", raises=(ValueError, isodate.ISO8601Error))
212-
def is_date(instance):
214+
def is_datetime(instance):
213215
if not isinstance(instance, str_types):
214216
return True
215217
return isodate.parse_datetime(instance)
216218
else:
217219
@_checks_drafts("date-time")
218-
def is_date(instance):
220+
def is_datetime(instance):
219221
if not isinstance(instance, str_types):
220222
return True
221223
return strict_rfc3339.validate_rfc3339(instance)
@@ -250,7 +252,6 @@ def is_time(instance):
250252
def is_css_color_code(instance):
251253
return webcolors.normalize_hex(instance)
252254

253-
254255
@_checks_drafts(draft3="color", raises=(ValueError, TypeError))
255256
def is_css21_color(instance):
256257
if (
@@ -260,7 +261,6 @@ def is_css21_color(instance):
260261
return True
261262
return is_css_color_code(instance)
262263

263-
264264
def is_css3_color(instance):
265265
if instance.lower() in webcolors.css3_names_to_hex:
266266
return True

jsonschema/_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def properties_draft3(validator, properties, instance, schema):
255255

256256
def disallow_draft3(validator, disallow, instance, schema):
257257
for disallowed in _utils.ensure_list(disallow):
258-
if validator.is_valid(instance, {"type" : [disallowed]}):
258+
if validator.is_valid(instance, {"type": [disallowed]}):
259259
yield ValidationError(
260260
"%r is disallowed for %r" % (disallowed, instance)
261261
)

jsonschema/cli.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,28 @@ def _json_file(path):
2626
action="append",
2727
dest="instances",
2828
type=_json_file,
29-
help="a path to a JSON instance (i.e. filename.json)"
30-
"to validate (may be specified multiple times)",
29+
help=(
30+
"a path to a JSON instance (i.e. filename.json)"
31+
"to validate (may be specified multiple times)"
32+
),
3133
)
3234
parser.add_argument(
3335
"-F", "--error-format",
3436
default="{error.instance}: {error.message}\n",
35-
help="the format to use for each error output message, specified in "
36-
"a form suitable for passing to str.format, which will be called "
37-
"with 'error' for each error",
37+
help=(
38+
"the format to use for each error output message, specified in "
39+
"a form suitable for passing to str.format, which will be called "
40+
"with 'error' for each error"
41+
),
3842
)
3943
parser.add_argument(
4044
"-V", "--validator",
4145
type=_namedAnyWithDefault,
42-
help="the fully qualified object name of a validator to use, or, for "
43-
"validators that are registered with jsonschema, simply the name "
44-
"of the class.",
46+
help=(
47+
"the fully qualified object name of a validator to use, or, for "
48+
"validators that are registered with jsonschema, simply the name "
49+
"of the class."
50+
),
4551
)
4652
parser.add_argument(
4753
"schema",

jsonschema/exceptions.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ def __init__(
5656
def __repr__(self):
5757
return "<%s: %r>" % (self.__class__.__name__, self.message)
5858

59-
def __str__(self):
60-
return unicode(self).encode("utf-8")
61-
6259
def __unicode__(self):
6360
essential_for_verbose = (
6461
self.validator, self.validator_value, self.instance, self.schema,
@@ -86,6 +83,9 @@ def __unicode__(self):
8683

8784
if PY3:
8885
__str__ = __unicode__
86+
else:
87+
def __str__(self):
88+
return unicode(self).encode("utf-8")
8989

9090
@classmethod
9191
def create_from(cls, other):
@@ -142,9 +142,6 @@ def __init__(self, type, instance, schema):
142142
self.instance = instance
143143
self.schema = schema
144144

145-
def __str__(self):
146-
return unicode(self).encode("utf-8")
147-
148145
def __unicode__(self):
149146
pschema = pprint.pformat(self.schema, width=72)
150147
pinstance = pprint.pformat(self.instance, width=72)
@@ -159,7 +156,9 @@ def __unicode__(self):
159156

160157
if PY3:
161158
__str__ = __unicode__
162-
159+
else:
160+
def __str__(self):
161+
return unicode(self).encode("utf-8")
163162

164163

165164
class FormatError(Exception):
@@ -168,14 +167,14 @@ def __init__(self, message, cause=None):
168167
self.message = message
169168
self.cause = self.__cause__ = cause
170169

171-
def __str__(self):
172-
return self.message.encode("utf-8")
173-
174170
def __unicode__(self):
175171
return self.message
176172

177173
if PY3:
178174
__str__ = __unicode__
175+
else:
176+
def __str__(self):
177+
return self.message.encode("utf-8")
179178

180179

181180
class ErrorTree(object):

jsonschema/tests/test_exceptions.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ def best_match(self, errors):
1010
errors = list(errors)
1111
best = exceptions.best_match(errors)
1212
reversed_best = exceptions.best_match(reversed(errors))
13+
msg = "Didn't return a consistent best match!\nGot: {0}\n\nThen: {1}"
1314
self.assertEqual(
14-
best,
15-
reversed_best,
16-
msg="Didn't return a consistent best match!\n"
17-
"Got: {0}\n\nThen: {1}".format(best, reversed_best),
15+
best, reversed_best, msg=msg.format(best, reversed_best),
1816
)
1917
return best
2018

jsonschema/validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Sequence, urljoin, urlsplit, urldefrag, unquote, urlopen,
1515
str_types, int_types, iteritems, lru_cache,
1616
)
17-
from jsonschema.exceptions import ErrorTree # Backwards compatibility # noqa
17+
from jsonschema.exceptions import ErrorTree # Backwards compat # noqa: F401
1818
from jsonschema.exceptions import RefResolutionError, SchemaError, UnknownType
1919

2020

@@ -51,7 +51,7 @@ def _validates(cls):
5151
return _validates
5252

5353

54-
def create(meta_schema, validators=(), version=None, default_types=None): # noqa
54+
def create(meta_schema, validators=(), version=None, default_types=None): # noqa: C901, E501
5555
if default_types is None:
5656
default_types = {
5757
u"array": list, u"boolean": bool, u"integer": int_types,
@@ -329,7 +329,7 @@ def pop_scope(self):
329329
raise RefResolutionError(
330330
"Failed to pop the scope from an empty stack. "
331331
"`pop_scope()` should only be called once for every "
332-
"`push_scope()`",
332+
"`push_scope()`"
333333
)
334334

335335
@property

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ commands =
6060

6161

6262
[flake8]
63-
ignore = E203,E302,E303,E701,F811
63+
exclude = jsonschema/_reflect.py

0 commit comments

Comments
 (0)