Nitrokey / pynitrokey

Python client for Nitrokey devices
Apache License 2.0
93 stars 28 forks source link

Enable type checks for nethsm code #442

Closed robin-nitrokey closed 9 months ago

robin-nitrokey commented 9 months ago

The updated NetHSM API client includes type annotations so we should be able to remove this exception:

https://github.com/Nitrokey/pynitrokey/blob/dc48ea4fb6c3dc2179dea818f2dc909c07ca4e78/pyproject.toml#L96-L99

And maybe also add the module to the strict checks:

https://github.com/Nitrokey/pynitrokey/blob/dc48ea4fb6c3dc2179dea818f2dc909c07ca4e78/pyproject.toml#L85-L94

A quick test causes a few error messages though:

pynitrokey/nethsm/client/paths/keys_generate/post/responses/response_201/__init__.py:19: error: Attributes without a default cannot follow attributes with one  [misc]
pynitrokey/nethsm/client/paths/keys/post/responses/response_201/__init__.py:19: error: Attributes without a default cannot follow attributes with one  [misc]
pynitrokey/nethsm/client/components/schema/public_key.py:78: error: Incompatible types in assignment (expression has type "str", variable has type "Union[Mapping[str, Union[dict[Any, Any], immutabledict[Any, Any], Mapping[str, object], list[Any], tuple[Any, ...], float, int, str, date, datetime, UUID, bool, None, bytes, io.FileIO, BufferedReader, pynitrokey.nethsm.client.schemas.schema.FileIO]], KeyPublicDataDict, Unset]")  [assignment]
pynitrokey/nethsm/client/components/schema/public_key.py:83: error: Invalid index type "Union[Mapping[str, Union[dict[Any, Any], immutabledict[Any, Any], Mapping[str, object], list[Any], tuple[Any, ...], float, int, str, date, datetime, UUID, bool, None, bytes, io.FileIO, BufferedReader, pynitrokey.nethsm.client.schemas.schema.FileIO]], KeyPublicDataDict, Unset]" for "dict[str, Any]"; expected type "str"  [index]
pynitrokey/nethsm/client/components/schema/private_key.py:73: error: Incompatible types in assignment (expression has type "str", variable has type "Union[Mapping[str, Union[dict[Any, Any], immutabledict[Any, Any], Mapping[str, object], list[Any], tuple[Any, ...], float, int, str, date, datetime, UUID, bool, None, bytes, io.FileIO, BufferedReader, pynitrokey.nethsm.client.schemas.schema.FileIO]], KeyPrivateDataDict]")  [assignment]
pynitrokey/nethsm/client/components/schema/private_key.py:78: error: Invalid index type "Union[Mapping[str, Union[dict[Any, Any], immutabledict[Any, Any], Mapping[str, object], list[Any], tuple[Any, ...], float, int, str, date, datetime, UUID, bool, None, bytes, io.FileIO, BufferedReader, pynitrokey.nethsm.client.schemas.schema.FileIO]], KeyPrivateDataDict]" for "dict[str, Any]"; expected type "str"  [index]

And the generated code still has many untyped defs.

nponsard commented 9 months ago

With #450 moving the generated client to a separate repository, I moved the issue here : https://github.com/Nitrokey/nethsm-sdk-py/issues/32