Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/check_datapackage/read_json.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from json import JSONDecodeError, loads
from pathlib import Path
from typing import Any
from typing import Any, cast


def read_json(path: Path) -> dict[str, Any]:
Expand All @@ -19,7 +19,7 @@ def read_json(path: Path) -> dict[str, Any]:
dictionary.
"""
try:
descriptor: Any = loads(path.read_text())
properties: Any = loads(path.read_text())
except JSONDecodeError as error:
raise JSONDecodeError(
f"The path {path} couldn't be parsed as JSON. Is there a typo or other "
Expand All @@ -28,11 +28,11 @@ def read_json(path: Path) -> dict[str, Any]:
pos=error.pos,
) from None # To hide the original traceback

if not isinstance(descriptor, dict):
if not isinstance(properties, dict):
raise TypeError(
f"The file {path} should parse into a Python dictionary (`dict`) "
f"but it converts to the type `{type(descriptor)}`. Is the file "
f"but it converts to the type `{type(properties)}`. Is the file "
"missing a curly bracket `{` at the beginning or `}` at the end?"
)
) from None # To hide the original traceback

return descriptor
return cast(dict[str, Any], properties)
Loading
Loading