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

Better typing (response class and issue with .get, .post, ...) #490

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

novitae
Copy link
Contributor

@novitae novitae commented Jan 27, 2025

This PR includes two things:

  • In my previous PR to make the methods .get, .post, .put, ..., I forgot to add total=False in the TypedDict they were unpacking, which was getting the type hint to say Any.

    • Before:
      Capture d’écran 2025-01-27 à 22 18 09
    • After:
      Capture d’écran 2025-01-27 à 22 18 57
  • A type hint for the response class. The results of requests were always an object Response, even if the response_class was changed. Now, if the response_class argument is set, the result hint will be an instance of this argument. Here is what it does:
    Capture d’écran 2025-01-27 à 22 19 34

@@ -20,6 +20,7 @@
Union,
cast,
)
from typing_extensions import TypeVar, Generic
Copy link
Owner

Choose a reason for hiding this comment

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

Let's make the typing_extensions an optional dependency.

Copy link
Contributor Author

@novitae novitae Jan 28, 2025

Choose a reason for hiding this comment

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

The TypeVar from typing only supports the default argument since python 3.12. Without this argument, the response class hint is broken, that's why I was importing it via typing_extension. I changed that.

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.

2 participants