Skip to content

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

Closed
lealre wants to merge 3 commits intoKludex:masterfrom
lealre:testclient-choose-redirect-arg-branch
Closed

fix: change conditional logic in _choose_redirect_arg for TestClent (#2783).#2805
lealre wants to merge 3 commits intoKludex:masterfrom
lealre:testclient-choose-redirect-arg-branch

Conversation

@lealre
Copy link
Copy Markdown
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
Copy Markdown
Owner

@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.

) -> 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
Copy Markdown
Owner

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:
message = "The `allow_redirects` argument is deprecated. Use `follow_redirects` instead."
warnings.warn(message, DeprecationWarning)
Copy link
Copy Markdown
Owner

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Owner

@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
Copy Markdown
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
Copy Markdown
Owner

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
Copy Markdown
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.

@Kludex
Copy link
Copy Markdown
Owner

Kludex commented Dec 25, 2024

Closing this in favor of #2808

@Kludex Kludex closed this Dec 25, 2024
@lealre lealre deleted the testclient-choose-redirect-arg-branch branch December 25, 2024 12:49
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