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

Correctly type vary_on_headers decorator #1340

Closed
intgr opened this issue Jan 24, 2023 · 4 comments · Fixed by #1370
Closed

Correctly type vary_on_headers decorator #1340

intgr opened this issue Jan 24, 2023 · 4 comments · Fixed by #1370
Labels
bug Something isn't working stubs Issues in stubs files (.pyi)

Comments

@intgr
Copy link
Collaborator

intgr commented Jan 24, 2023

What's wrong

Noticed this while reviewing #1339. The vary_on_headers decorator doesn't preserve the type (arguments and return) when used on a function.

@intgr intgr added bug Something isn't working stubs Issues in stubs files (.pyi) labels Jan 24, 2023
@RyanWalker277
Copy link
Contributor

Hey @intgr @adamchainz! Wanted to ask a few things about this one. In https://github.com/typeddjango/django-stubs/blob/master/django-stubs/views/decorators/vary.pyi , what does the definition of vary_on_headers here imply? Are we overriding the decorator funciton here? One approach I could think of is wrapping the whole definition into functools.wraps decorator. Not sure how good that would be or whether it would even work or not? Would appreciate your feedback!

@intgr
Copy link
Collaborator Author

intgr commented Feb 16, 2023

functools.wraps doesn't help AFAIK. I could be wrong.

There are lots of examples of decorators already, I think you can look at require_http_methods which behaves similarly.

Here's mypy documentation on type hinting decorators: https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators

@adamchainz
Copy link
Contributor

Please don't @ particular people on issues, those who have notifications will notice.

@RyanWalker277
Copy link
Contributor

I have raised a PR ( #1370 ) for this. For a more accurate type annotation, I utilised a parameter specification (ParamSpec). Kindly review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stubs Issues in stubs files (.pyi)
Development

Successfully merging a pull request may close this issue.

3 participants