Skip to content

Commit b0c97c9

Browse files
committed
Address feedback
1 parent 475e0a0 commit b0c97c9

File tree

5 files changed

+14
-21
lines changed

5 files changed

+14
-21
lines changed

src/check_jsonschema/cli/main_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def pretty_helptext_list(values: list[str] | tuple[str, ...]) -> str:
163163
)
164164
@click.option(
165165
"--force-filetype",
166-
help="Force a file typr to use for the file",
166+
help="Force a file type to use when parsing instance files",
167167
type=click.Choice(SUPPORTED_FILE_FORMATS, case_sensitive=True),
168168
)
169169
@click.option(

src/check_jsonschema/parsers/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,14 @@ def get(
6868
self,
6969
path: pathlib.Path | str,
7070
default_filetype: str,
71-
force_filetype: str | None,
71+
force_filetype: str | None = None,
7272
) -> t.Callable[[t.IO[bytes]], t.Any]:
73-
filetype = path_to_type(path, default_type=default_filetype)
73+
if force_filetype:
74+
filetype = force_filetype
75+
else:
76+
filetype = path_to_type(path, default_type=default_filetype)
7477

7578
if filetype in self._by_tag:
76-
filetype = force_filetype or filetype
77-
7879
return self._by_tag[filetype]
7980

8081
if filetype in MISSING_SUPPORT_MESSAGES:
@@ -92,7 +93,7 @@ def parse_data_with_path(
9293
data: t.IO[bytes] | bytes,
9394
path: pathlib.Path | str,
9495
default_filetype: str,
95-
force_filetype: str | None,
96+
force_filetype: str | None = None,
9697
) -> t.Any:
9798
loadfunc = self.get(path, default_filetype, force_filetype)
9899
try:
@@ -106,7 +107,7 @@ def parse_file(
106107
self,
107108
path: pathlib.Path | str,
108109
default_filetype: str,
109-
force_filetype: str | None,
110+
force_filetype: str | None = None,
110111
) -> t.Any:
111112
with open(path, "rb") as fp:
112113
return self.parse_data_with_path(fp, path, default_filetype, force_filetype)

src/check_jsonschema/schema_loader/readers.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ def get_retrieval_uri(self) -> str | None:
4444
return self.path.as_uri()
4545

4646
def _read_impl(self) -> t.Any:
47-
return self.parsers.parse_file(
48-
self.path, default_filetype="json", force_filetype=None
49-
)
47+
return self.parsers.parse_file(self.path, default_filetype="json")
5048

5149
def read_schema(self) -> dict:
5250
if self._parsed_schema is _UNSET:
@@ -86,10 +84,7 @@ def __init__(
8684

8785
def _parse(self, schema_bytes: bytes) -> t.Any:
8886
return self.parsers.parse_data_with_path(
89-
io.BytesIO(schema_bytes),
90-
self.url,
91-
default_filetype="json",
92-
force_filetype=None,
87+
io.BytesIO(schema_bytes), self.url, default_filetype="json"
9388
)
9489

9590
def get_retrieval_uri(self) -> str | None:

src/check_jsonschema/schema_loader/resolver.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def create_retrieve_callable(
5454

5555
def get_local_file(uri: str) -> t.Any:
5656
path = filename2path(uri)
57-
return parser_set.parse_file(path, "json", None)
57+
return parser_set.parse_file(path, "json")
5858

5959
def retrieve_reference(uri: str) -> referencing.Resource[Schema]:
6060
scheme = urllib.parse.urlsplit(uri).scheme
@@ -70,17 +70,15 @@ def retrieve_reference(uri: str) -> referencing.Resource[Schema]:
7070
if full_uri_scheme in ("http", "https"):
7171

7272
def validation_callback(content: bytes) -> None:
73-
parser_set.parse_data_with_path(content, full_uri, "json", None)
73+
parser_set.parse_data_with_path(content, full_uri, "json")
7474

7575
bound_downloader = downloader.bind(
7676
full_uri, validation_callback=validation_callback
7777
)
7878
with bound_downloader.open() as fp:
7979
data = fp.read()
8080

81-
parsed_object = parser_set.parse_data_with_path(
82-
data, full_uri, "json", None
83-
)
81+
parsed_object = parser_set.parse_data_with_path(data, full_uri, "json")
8482
else:
8583
parsed_object = get_local_file(full_uri)
8684

tests/unit/test_instance_loader.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def test_instanceloader_force_filetype_toml(
103103
assert data == [(str(f), {"foo": {"bar": "baz"}})]
104104

105105

106+
@pytest.mark.skipif(not JSON5_ENABLED, reason="test requires json5")
106107
@pytest.mark.parametrize(
107108
"filename, force_filetype",
108109
[
@@ -113,8 +114,6 @@ def test_instanceloader_force_filetype_toml(
113114
def test_instanceloader_force_filetype_json(
114115
tmp_path, filename, force_filetype, open_wide
115116
):
116-
if not JSON5_ENABLED:
117-
pytest.skip("test requires json5")
118117
f = tmp_path / filename
119118
f.write_text("// a comment\n{}")
120119
loader = InstanceLoader(open_wide(f), force_filetype=force_filetype)

0 commit comments

Comments
 (0)