Skip to content

Commit

Permalink
improve JSON typing to reduce false-positive typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault committed Aug 31, 2023
1 parent dea3bf8 commit 1a696e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions magpie/typedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@

AnyKey = Union[Str, int]
AnyValue = Union[Str, Number, bool, None]
_JSONType = "JSON" # type: TypeAlias # pylint: disable=C0103
BaseJSON = Union[AnyValue, List[_JSONType], Dict[AnyKey, _JSONType]]
JSON = Union[Dict[Str, Union[_JSONType]], List[_JSONType]]
_JSON = "JSON" # type: TypeAlias # pylint: disable=C0103
_JsonObjectItemAlias = "_JsonObjectItem" # type: TypeAlias # pylint: disable=C0103
_JsonListItemAlias = "_JsonListItem" # type: TypeAlias # pylint: disable=C0103
_JsonObjectItem = Dict[str, Union[AnyValue, _JSON, _JsonObjectItemAlias, _JsonListItemAlias]]
_JsonListItem = List[Union[AnyValue, _JSON, _JsonObjectItem, _JsonListItemAlias]]
_JsonItem = Union[AnyValue, _JSON, _JsonObjectItem, _JsonListItem]
JSON = Union[Dict[str, Union[_JSON, _JsonItem]], List[Union[_JSON, _JsonItem]], AnyValue]

GroupPriority = Union[int, Type[math.inf]]
UserServicesType = Union[Dict[Str, Dict[Str, Any]], List[Dict[Str, Any]]]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_magpie_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def setUpClass(cls):
cls.version = utils.TestSetup.get_Version(cls, real_version=True)
cls.setup_admin()
cls.headers, cls.cookies = utils.check_or_try_login_user(cls, cls.usr, cls.pwd, use_ui_form_submit=True)
cls.require = "cannot run tests without logged in user with '{}' permissions".format(cls.grp)
cls.require = "cannot run tests without logged-in user with '{}' permissions".format(cls.grp)
assert cls.headers and cls.cookies, cls.require # nosec

cls.test_service_name = "unittest-user-auth-remote_test-service"
Expand Down Expand Up @@ -688,4 +688,4 @@ def raise_request(*_, **__):

if __name__ == "__main__":
import sys
sys.exit(unittest.main())
sys.exit(unittest.main()) # type: ignore

0 comments on commit 1a696e9

Please sign in to comment.