Skip to content

prefer more generic Mapping over dict type#10

Merged
edvardm merged 2 commits intomainfrom
typing/generic-mapping-type-for-headers
Jul 16, 2024
Merged

prefer more generic Mapping over dict type#10
edvardm merged 2 commits intomainfrom
typing/generic-mapping-type-for-headers

Conversation

@edvardm
Copy link
Copy Markdown

@edvardm edvardm commented Jul 11, 2024

typically it's better to specify more generic types for input parameters, and specific types our return values. In this case changing headers param from dict to Mapping should resolve typing issues when eg. starlette.requests.headers.Headers instance is passed to get_principal_from_headers()

Comment thread audit_log/headers.py
@edvardm edvardm marked this pull request as ready for review July 11, 2024 09:34
@edvardm edvardm requested a review from a team as a code owner July 11, 2024 09:34
Copy link
Copy Markdown
Contributor

@sinanislekdemir sinanislekdemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, from the official docs. I haven't noticed this before.
Makes sense 🤔

https://docs.python.org/3/library/typing.html#typing.Dict

image

Comment thread audit_log/headers.py Outdated
@edvardm edvardm requested a review from jerr0328 July 11, 2024 15:30
Edvard Majakari added 2 commits July 16, 2024 10:59
typically it's better to specify more generic types for input parameters,
and specific types our return values. In this case changing headers
param from dict to Mapping should resolve typing issues when eg.
starlette.requests.headers.Headers instance is passed to
get_principal_from_headers()
@edvardm edvardm force-pushed the typing/generic-mapping-type-for-headers branch from e1c290d to 54239c8 Compare July 16, 2024 10:59
@edvardm edvardm merged commit 98aa39a into main Jul 16, 2024
@edvardm edvardm deleted the typing/generic-mapping-type-for-headers branch July 16, 2024 11:05
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.

3 participants