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

fix: change conditional logic in _choose_redirect_arg for TestClent (#2783). #2805

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lealre
Copy link
Contributor

@lealre lealre commented Dec 16, 2024

Summary

Related to issue #2783

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

Copy link
Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

I forgot to press "comment". I reviewed yesterday.

@@ -449,16 +449,16 @@ def _choose_redirect_arg(
self, follow_redirects: bool | None, allow_redirects: bool | None
) -> bool | httpx._client.UseClientDefault:
redirect: bool | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT
if allow_redirects is not None and follow_redirects is not None:
raise RuntimeError( # pragma: no cover
Copy link
Member

Choose a reason for hiding this comment

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

We can test it now.

if allow_redirects is not None and follow_redirects is not None:
raise RuntimeError( # pragma: no cover
"Cannot use both `allow_redirects` and `follow_redirects`."
)
if allow_redirects is not None:
message = "The `allow_redirects` argument is deprecated. Use `follow_redirects` instead."
warnings.warn(message, DeprecationWarning)
Copy link
Member

Choose a reason for hiding this comment

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

When did we add this line? Maybe we should just remove this logic... 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that it was added here.

I will work on the test, and if you decide that it should be removed, I will remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw that the allow_redirects was being covered in tests because it was being used in test_responses.py and in tests/middleware/test_https_redirect.py.

I changed it to follow_redirects as allow_redirects is deprecated and added tests to cover all the cases in test_testclient.

Copy link
Member

@Kludex Kludex left a comment

Choose a reason for hiding this comment

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

I've been thinking about this...

We added the RuntimeError logic to make sure people would not use the two parameters. At the time, it was a good idea. Nowadays, it's been two years since we added this function. I think we should just drop the _choose_redirect_arg.

The deprecation warning has been there for long, so I think it's fine.

@lealre Would you like to create a PR with it?

@lealre
Copy link
Contributor Author

lealre commented Dec 22, 2024

I think we should just drop the _choose_redirect_arg.

The deprecation warning has been there for long, so I think it's fine.

@lealre Would you like to create a PR with it?

Yes, I would like to work on it.

So, just to confirm, it will remove the _choose_redirect_arg and keep only the follow_redirects argument in TestClient.

@Kludex
Copy link
Member

Kludex commented Dec 22, 2024

No, the goal is to remove the deprecated parameter. The function doesn't make sense without the parameter.

@lealre
Copy link
Contributor Author

lealre commented Dec 22, 2024

So, just to confirm, it will remove the _choose_redirect_arg and keep only the follow_redirects argument in TestClient.

Yes, I meant to keep the follow_redirects and remove the deprecated allow_redirects.

EDIT: Makes more sense to pass httpx._client.USE_CLIENT_DEFAULT as a default argument.

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