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

Refactor httpx/_utils.py #1943

Merged
merged 9 commits into from
Feb 9, 2022
Merged

Refactor httpx/_utils.py #1943

merged 9 commits into from
Feb 9, 2022

Conversation

yezz123
Copy link
Contributor

@yezz123 yezz123 commented Nov 18, 2021

Based on what @tomchristie recommended to make #1909 this PR into a shorter one to validate multiple things and let it more clear and ready for review.

self.host_regex = re.compile(f"^{domain}$")
# example.com should match "example.com" but not "www.example.com"
domain = re.escape(url.host)
self.host_regex = re.compile(f"^{domain}$")
Copy link
Member

Choose a reason for hiding this comment

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

I like the refactoring you've done on this block, yup. I think it makes enough of a readability difference that it's worth having in.

httpx/_utils.py Outdated Show resolved Hide resolved
httpx/_utils.py Outdated
@@ -23,7 +23,7 @@
{chr(c): "%{:02X}".format(c) for c in range(0x1F + 1) if c != 0x1B}
)
_HTML5_FORM_ENCODING_RE = re.compile(
r"|".join([re.escape(c) for c in _HTML5_FORM_ENCODING_REPLACEMENTS.keys()])
r"|".join([re.escape(c) for c in _HTML5_FORM_ENCODING_REPLACEMENTS])
Copy link
Member

Choose a reason for hiding this comment

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

I could go either way on this one. Possibly it's more obvious with .keys() what the effect is. Possibly not. But, okay, sure.

@tomchristie
Copy link
Member

Okay, I've reverted one elif change that was just dangling on its own.
The other two changes make sense.

@tomchristie tomchristie added the refactor Issues and PRs related to code refactoring label Nov 22, 2021
@yezz123
Copy link
Contributor Author

yezz123 commented Nov 23, 2021

Okay, I've reverted one elif change that was just dangling on its own. The other two changes make sense.

@tomchristie that's great, if there is any other things we can discuss about it and fix it 🚀

httpx/_utils.py Outdated Show resolved Hide resolved
@tomchristie
Copy link
Member

I've reverted the minor change to _HTML5_FORM_ENCODING_RE - it's unrelated to the elif block changes.

Given that I think those are a clear win, let's just pull those in as a single nicely scoped pull request.

Copy link
Member

@tomchristie tomchristie left a comment

Choose a reason for hiding this comment

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

Nice little improvement to the flow there, thank you!

@tomchristie tomchristie merged commit a416106 into encode:master Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Issues and PRs related to code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants