feat/improve-bytes-subclass-mypy-support #130
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.