Skip to content

Commit af858bf

Browse files
committed
Update linters
1 parent 639c91f commit af858bf

File tree

8 files changed

+81
-52
lines changed

8 files changed

+81
-52
lines changed

deps/check.in

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Top-level dependencies for `tox -e check`
22
flake8
3+
flake8-2020
34
flake8-bandit
45
flake8-bugbear
56
flake8-builtins
67
flake8-comprehensions
8+
flake8-datetimez
79
flake8-docstrings
10+
flake8-mutable
11+
# flake8-noqa # See https://github.com/JBKahn/flake8-print/issues/50
812
flake8-print
13+
flake8-simplify
14+
flake8-strftime
915
mypy
1016
pep8-naming
1117
shed
12-
com2ann # via shed; workaround for missing python_requires

deps/check.txt

+38-18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# pip-compile --output-file=deps/check.txt deps/check.in
66
#
7+
astor==0.8.1
8+
# via flake8-simplify
79
attrs==21.2.0
810
# via flake8-bugbear
911
autoflake==1.4
@@ -12,50 +14,70 @@ bandit==1.7.0
1214
# via flake8-bandit
1315
black==21.9b0
1416
# via shed
15-
click==8.0.1
17+
click==8.0.3
1618
# via black
1719
colorama==0.4.4
1820
# via
1921
# bandit
2022
# click
21-
com2ann==0.1.1
22-
# via -r deps/check.in
23-
flake8==3.9.2
23+
com2ann==0.3.0
24+
# via shed
25+
flake8==4.0.1
2426
# via
2527
# -r deps/check.in
28+
# flake8-2020
2629
# flake8-bandit
2730
# flake8-bugbear
2831
# flake8-builtins
2932
# flake8-comprehensions
33+
# flake8-datetimez
3034
# flake8-docstrings
35+
# flake8-helper
36+
# flake8-mutable
3137
# flake8-polyfill
3238
# flake8-print
39+
# flake8-simplify
40+
# flake8-strftime
3341
# pep8-naming
42+
flake8-2020==1.6.0
43+
# via -r deps/check.in
3444
flake8-bandit==2.1.2
3545
# via -r deps/check.in
3646
flake8-bugbear==21.9.2
3747
# via -r deps/check.in
3848
flake8-builtins==1.5.3
3949
# via -r deps/check.in
40-
flake8-comprehensions==3.6.1
50+
flake8-comprehensions==3.7.0
51+
# via -r deps/check.in
52+
flake8-datetimez==20.10.0
4153
# via -r deps/check.in
4254
flake8-docstrings==1.6.0
4355
# via -r deps/check.in
56+
flake8-helper==0.1.1
57+
# via flake8-strftime
58+
flake8-mutable==1.2.0
59+
# via -r deps/check.in
4460
flake8-polyfill==1.0.2
4561
# via
4662
# flake8-bandit
4763
# pep8-naming
4864
flake8-print==4.0.0
4965
# via -r deps/check.in
50-
gitdb==4.0.7
66+
flake8-simplify==0.14.2
67+
# via -r deps/check.in
68+
flake8-strftime==0.3.2
69+
# via -r deps/check.in
70+
gitdb==4.0.9
5171
# via gitpython
5272
gitpython==3.1.24
5373
# via bandit
54-
importlib-metadata==4.8.1
74+
importlib-metadata==4.2.0
5575
# via
5676
# click
5777
# flake8
78+
# flake8-2020
5879
# flake8-comprehensions
80+
# flake8-simplify
5981
# stevedore
6082
isort==5.9.3
6183
# via shed
@@ -78,42 +100,42 @@ pep8-naming==0.12.1
78100
# via -r deps/check.in
79101
platformdirs==2.4.0
80102
# via black
81-
pycodestyle==2.7.0
103+
pycodestyle==2.8.0
82104
# via
83105
# flake8
84106
# flake8-bandit
85107
# flake8-print
86108
pydocstyle==6.1.1
87109
# via flake8-docstrings
88-
pyflakes==2.3.1
110+
pyflakes==2.4.0
89111
# via
90112
# autoflake
91113
# flake8
92114
pyupgrade==2.29.0
93115
# via shed
94-
pyyaml==5.4.1
116+
pyyaml==6.0
95117
# via
96118
# bandit
97119
# libcst
98-
regex==2021.9.30
120+
regex==2021.10.23
99121
# via black
100-
shed==0.5.0
122+
shed==0.5.3
101123
# via -r deps/check.in
102124
six==1.16.0
103125
# via
104126
# bandit
105127
# flake8-print
106-
smmap==4.0.0
128+
smmap==5.0.0
107129
# via gitdb
108130
snowballstemmer==2.1.0
109131
# via pydocstyle
110-
stevedore==3.4.0
132+
stevedore==3.5.0
111133
# via bandit
112-
tokenize-rt==4.1.0
134+
tokenize-rt==4.2.1
113135
# via pyupgrade
114136
toml==0.10.2
115137
# via mypy
116-
tomli==1.2.1
138+
tomli==1.2.2
117139
# via black
118140
typed-ast==1.4.3
119141
# via
@@ -129,5 +151,3 @@ typing-extensions==3.10.0.2
129151
# typing-inspect
130152
typing-inspect==0.7.1
131153
# via libcst
132-
zipp==3.6.0
133-
# via importlib-metadata

deps/test.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# pip-compile --output-file=deps/test.txt deps/test.in setup.py
66
#
7-
arrow==1.2.0
7+
arrow==1.2.1
88
# via isoduration
99
atomicwrites==1.4.0
1010
# via pytest
@@ -17,15 +17,15 @@ cached-property==1.5.2
1717
# via fqdn
1818
colorama==0.4.4
1919
# via pytest
20-
coverage==6.0
20+
coverage[toml]==6.0.2
2121
# via pytest-cov
2222
execnet==1.9.0
2323
# via pytest-xdist
2424
fqdn==1.5.1
2525
# via jsonschema
26-
hypothesis==6.23.1
26+
hypothesis==6.24.0
2727
# via hypothesis-jsonschema (setup.py)
28-
idna==3.2
28+
idna==3.3
2929
# via jsonschema
3030
importlib-metadata==4.8.1
3131
# via
@@ -38,7 +38,7 @@ isoduration==20.11.0
3838
# via jsonschema
3939
jsonpointer==2.1
4040
# via jsonschema
41-
jsonschema[format]==4.0.1
41+
jsonschema[format]==4.1.2
4242
# via
4343
# -r deps/test.in
4444
# hypothesis-jsonschema (setup.py)
@@ -50,7 +50,7 @@ py==1.10.0
5050
# via
5151
# pytest
5252
# pytest-forked
53-
pyparsing==2.4.7
53+
pyparsing==3.0.1
5454
# via packaging
5555
pyrsistent==0.18.0
5656
# via jsonschema
@@ -60,7 +60,7 @@ pytest==6.2.5
6060
# pytest-cov
6161
# pytest-forked
6262
# pytest-xdist
63-
pytest-cov==2.12.1
63+
pytest-cov==3.0.0
6464
# via -r deps/test.in
6565
pytest-forked==1.3.0
6666
# via pytest-xdist
@@ -79,9 +79,9 @@ six==1.16.0
7979
sortedcontainers==2.4.0
8080
# via hypothesis
8181
toml==0.10.2
82-
# via
83-
# pytest
84-
# pytest-cov
82+
# via pytest
83+
tomli==1.2.2
84+
# via coverage
8585
typing-extensions==3.10.0.2
8686
# via
8787
# arrow

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import pathlib
23

34
import setuptools
45

@@ -46,7 +47,7 @@ def local_file(name: str) -> str:
4647
"Topic :: Software Development :: Testing",
4748
"Typing :: Typed",
4849
],
49-
long_description=open(README).read(),
50+
long_description=pathlib.Path(README).read_text(),
5051
long_description_content_type="text/markdown",
5152
keywords="python testing fuzzing property-based-testing json-schema",
5253
)

src/hypothesis_jsonschema/_canonicalise.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def canonicalish(schema: JSONType) -> Dict[str, Any]:
211211
This is obviously incomplete, but improves best-effort recognition of
212212
equivalent schemas and makes conversion logic simpler.
213213
"""
214-
if schema is True:
214+
if schema is True: # noqa: SIM114
215215
return {}
216216
elif schema is False:
217217
return {"not": {}}
@@ -245,13 +245,16 @@ def canonicalish(schema: JSONType) -> Dict[str, Any]:
245245
if_ = schema.pop("if", None)
246246
then = schema.pop("then", schema)
247247
else_ = schema.pop("else", schema)
248-
if if_ is not None and (then is not schema or else_ is not schema):
249-
if then not in (if_, TRUTHY) or else_ != TRUTHY:
250-
alternatives = [
251-
{"allOf": [if_, then, schema]},
252-
{"allOf": [{"not": if_}, else_, schema]},
253-
]
254-
schema = canonicalish({"anyOf": alternatives})
248+
if (
249+
if_ is not None
250+
and (then is not schema or else_ is not schema)
251+
and (then not in (if_, TRUTHY) or else_ != TRUTHY)
252+
):
253+
alternatives = [
254+
{"allOf": [if_, then, schema]},
255+
{"allOf": [{"not": if_}, else_, schema]},
256+
]
257+
schema = canonicalish({"anyOf": alternatives})
255258
assert isinstance(schema, dict)
256259
# Recurse into the value of each keyword with a schema (or list of them) as a value
257260
for key in SCHEMA_KEYS:
@@ -395,7 +398,7 @@ def canonicalish(schema: JSONType) -> Dict[str, Any]:
395398
type_.remove("object")
396399
# Discard dependencies values that don't restrict anything
397400
for k, v in schema.get("dependencies", {}).copy().items():
398-
if v == [] or v == TRUTHY:
401+
if v in ([], TRUTHY):
399402
schema["dependencies"].pop(k)
400403
# Remove no-op keywords
401404
for kw, identity in {
@@ -438,15 +441,13 @@ def canonicalish(schema: JSONType) -> Dict[str, Any]:
438441
max_ = schema.get("maxProperties", float("inf"))
439442
assert isinstance(max_, (int, float))
440443
properties = schema.get("properties", {})
441-
if len(schema["required"]) > max_:
442-
type_.remove("object")
443-
elif any(properties.get(name, {}) == FALSEY for name in schema["required"]):
444+
propnames_validator = make_validator(schema.get("propertyNames", {})).is_valid
445+
if (
446+
len(schema["required"]) > max_
447+
or any(properties.get(name, {}) == FALSEY for name in schema["required"])
448+
or not all(propnames_validator(name) for name in schema["required"])
449+
):
444450
type_.remove("object")
445-
else:
446-
propnames = schema.get("propertyNames", {})
447-
validator = make_validator(propnames)
448-
if not all(validator.is_valid(name) for name in schema["required"]):
449-
type_.remove("object")
450451

451452
for t, kw in TYPE_SPECIFIC_KEYS:
452453
numeric = {"number", "integer"}
@@ -719,7 +720,7 @@ def merged(schemas: List[Any]) -> Optional[Schema]:
719720
if "contains" in out and "contains" in s and out["contains"] != s["contains"]:
720721
# If one `contains` schema is a subset of the other, we can discard it.
721722
m = merged([out["contains"], s["contains"]])
722-
if m == out["contains"] or m == s["contains"]:
723+
if m in (out["contains"], s["contains"]):
723724
out["contains"] = m
724725
s.pop("contains")
725726
if "not" in out and "not" in s and out["not"] != s["not"]:

src/hypothesis_jsonschema/_from_schema.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ def zfill(width: int) -> Callable[[int], str]:
291291
return st.one_of(st.just("Z"), rfc3339("time-numoffset"))
292292
if name == "partial-time":
293293
return st.times().map(str)
294-
if name == "date" or name == "full-date":
294+
if name in ("date", "full-date"):
295295
return st.dates().map(str)
296-
if name == "time" or name == "full-time":
296+
if name in ("time", "full-time"):
297297
return st.tuples(rfc3339("partial-time"), rfc3339("time-offset")).map("".join)
298298
assert name == "date-time"
299299
return st.tuples(rfc3339("full-date"), rfc3339("full-time")).map("T".join)

tests/fetch.py

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def get_json(url: str) -> Any:
2121
return json.load(handle)
2222

2323

24+
"""
2425
# Load cached schemas, so we cope with flaky connections and keep deleted entries
2526
try:
2627
with open("tests/corpus-schemastore-catalog.json") as f:
@@ -54,6 +55,7 @@ def add_future(name: str, url: str) -> None:
5455
# Dump them all back to the catalog file.
5556
with open("tests/corpus-schemastore-catalog.json", mode="w") as f:
5657
json.dump(schemata, f, indent=4, sort_keys=True)
58+
"""
5759

5860

5961
# Part two: fetch the official jsonschema compatibility test suite

tests/test_version.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for the hypothesis-jsonschema library."""
22

33
import re
4-
from datetime import date
4+
from datetime import datetime, timezone
55
from functools import lru_cache
66
from pathlib import Path
77
from typing import NamedTuple
@@ -33,7 +33,7 @@ def get_releases():
3333
def test_last_release_against_changelog():
3434
last_version, last_date = get_releases()[0]
3535
assert last_version == Version.from_string(hypothesis_jsonschema.__version__)
36-
assert last_date <= date.today().isoformat()
36+
assert last_date <= datetime.now(timezone.utc).date().isoformat()
3737

3838

3939
def test_changelog_is_ordered():

0 commit comments

Comments
 (0)