diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 62506b3..82c8422 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,12 +6,12 @@ ci: repos: - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.7.0 hooks: - id: black - repo: https://github.com/pycqa/isort - rev: 5.11.4 + rev: 5.12.0 hooks: - id: isort args: ["--profile", "black", "--filter-files"] diff --git a/discatcore/http/client.py b/discatcore/http/client.py index f8d4bdc..917f41a 100644 --- a/discatcore/http/client.py +++ b/discatcore/http/client.py @@ -171,6 +171,9 @@ def _prepare_data( pd.json = _filter_dict_for_unset(json) if isinstance(json, dict) else json if json is not Unset and files is not Unset: + if t.TYPE_CHECKING: + files = t.cast(list[BasicFile], files) + form_dat = aiohttp.FormData() form_dat.add_field( "payload_json", diff --git a/requirements/dev.txt b/requirements/dev.txt index ebf89c6..9bbcd6a 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1 +1 @@ -pyright==1.1.279 +pyright==1.1.317 diff --git a/scripts/generate_endpoints.py b/scripts/generate_endpoints.py index 2d4a085..7012e2e 100644 --- a/scripts/generate_endpoints.py +++ b/scripts/generate_endpoints.py @@ -75,6 +75,7 @@ class UnsetType(Enum): # Function Creator # + # taken from typing # https://github.com/python/cpython/blob/3.10/Lib/typing.py#L185-L203 def _type_repr(obj: t.Any) -> str: @@ -272,7 +273,9 @@ def _dict_type_check( elif val is ...: return Unset - if isinstance(val, expected_type): + origin = t.get_origin(expected_type) + + if isinstance(val, origin or expected_type): return val raise TypeError(f"the value at key {key} is not of type {_type_repr(expected_type)}!") @@ -406,8 +409,8 @@ def parse_endpoint_func(name: str, func: dict[str, t.Any]) -> tuple[str, list[st def parse_json_file(file: dict[str, t.Any]) -> str: funcs: list[str] = [] name = _dict_type_check(file, "name", str) - methods: dict[str, t.Any] = _dict_type_check(file, "methods", dict) - requires: UnsetOr[list[str]] = _dict_type_check(file, "requires", list, is_required=False) + methods: dict[str, t.Any] = _dict_type_check(file, "methods", dict[str, t.Any]) + requires: UnsetOr[list[str]] = _dict_type_check(file, "requires", list[str], is_required=False) imports = "" used_imports: list[str] = []