Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/improve-bytes-subclass-mypy-support #130

Merged
merged 4 commits into from
Apr 28, 2022

Conversation

MasterKale
Copy link
Collaborator

@MasterKale MasterKale commented Apr 28, 2022

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:

Screen Shot 2022-04-27 at 11 03 15 AM

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.

@MasterKale MasterKale merged commit 517d7b9 into master Apr 28, 2022
@MasterKale MasterKale deleted the feat/improve-bytes-subclass-mypy-support branch April 28, 2022 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant