Attempting to use the latest py_webauthn in a codebase featuring stricter use of mypy than I'd set up here revealed issues with the use of BytesLike as a model field type. Namely, otherwise valid values like bytes and memoryview were not specifically instances of BytesLike, and mypy thus deemed them inappropriate input:
After some internal discussion with colleagues I chose to try and refactor the concept of BytesLike into types that would appease mypy while also supporting these more advanced bytes-adjacent values. This would aim to restore the ability to define model fields as bytes type, which is the type I otherwise want to assign.
This PR adds a new field validator to WebAuthnBaseModel that performs the coercion to bytes that was previously taken care of with BytesLike. This should maintain the core ability to pass in raw bytes values while defining Pydantic models in a way that makes mypy happy.
I've also updated this project's mypy config to help catch issues like this in the future.
Attempting to use the latest py_webauthn in a codebase featuring stricter use of mypy than I'd set up here revealed issues with the use of
BytesLike
as a model field type. Namely, otherwise valid values likebytes
andmemoryview
were not specifically instances ofBytesLike
, and mypy thus deemed them inappropriate input:After some internal discussion with colleagues I chose to try and refactor the concept of
BytesLike
into types that would appease mypy while also supporting these more advanced bytes-adjacent values. This would aim to restore the ability to define model fields asbytes
type, which is the type I otherwise want to assign.This PR adds a new field validator to
WebAuthnBaseModel
that performs the coercion tobytes
that was previously taken care of withBytesLike
. This should maintain the core ability to pass in rawbytes
values while defining Pydantic models in a way that makes mypy happy.I've also updated this project's mypy config to help catch issues like this in the future.