From 895bb1c7d542ae507717a15254b34ce1d885bdee Mon Sep 17 00:00:00 2001 From: Bill Peck Date: Tue, 24 Feb 2026 13:29:28 -0500 Subject: [PATCH] fix ruff linting errors --- httpx/_utils.py | 22 +++++++++++----------- tests/test_utils.py | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/httpx/_utils.py b/httpx/_utils.py index 4588a6df..03b09381 100644 --- a/httpx/_utils.py +++ b/httpx/_utils.py @@ -243,15 +243,15 @@ class WildcardURLPattern(Pattern): def __eq__(self, other: typing.Any) -> bool: return isinstance(other, WildcardURLPattern) and self.pattern == other.pattern - + class IPNetPattern(Pattern): def __init__(self, ip_net: str) -> None: try: - addr, range = ip_net.split('/', 1) - if addr[0] == '[' and addr[-1] == ']': + addr, range = ip_net.split("/", 1) + if addr[0] == "[" and addr[-1] == "]": addr = addr[1:-1] - ip_net = f'{addr}/{range}' + ip_net = f"{addr}/{range}" except ValueError: pass # not a range self.net = ipaddress.ip_network(ip_net) @@ -261,7 +261,7 @@ class IPNetPattern(Pattern): return ipaddress.ip_address(other.host) in self.net except ValueError: return False - + @property def priority(self) -> tuple[int, int, int]: return -1, 0, 0 # higher priority than URLPatterns @@ -274,17 +274,17 @@ class IPNetPattern(Pattern): def __eq__(self, other: typing.Any) -> bool: return isinstance(other, IPNetPattern) and self.net == other.net - + URLPattern = IPNetPattern | WildcardURLPattern def build_url_pattern(pattern: str) -> URLPattern: try: - proto, rest = pattern.split('://', 1) - if proto == 'all' and '/' in rest: - return IPNetPattern(rest) - except ValueError: # covers .split() and IPNetPattern + proto, rest = pattern.split("://", 1) + if proto == "all" and "/" in rest: + return IPNetPattern(rest) + except ValueError: # covers .split() and IPNetPattern pass return WildcardURLPattern(pattern) @@ -302,4 +302,4 @@ def is_ipv6_hostname(hostname: str) -> bool: ipaddress.IPv6Address(hostname.split("/")[0]) except Exception: return False - return True \ No newline at end of file + return True diff --git a/tests/test_utils.py b/tests/test_utils.py index 046818a2..d42570ed 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -128,10 +128,10 @@ def test_get_environment_proxies(environment, proxies): ("http://", "https://example.com", False), ("all://", "https://example.com:123", True), ("", "https://example.com:123", True), - ('all://192.168.0.0/24', 'http://192.168.0.1', True), - ('all://192.168.0.0/24', 'https://192.168.1.1', False), - ('all://[2001:db8:abcd:0012::]/64', 'http://[2001:db8:abcd:12::1]', True), - ('all://[2001:db8:abcd:0012::]/64', 'http://[2001:db8:abcd:13::1]:8080', False), + ("all://192.168.0.0/24", "http://192.168.0.1", True), + ("all://192.168.0.0/24", "https://192.168.1.1", False), + ("all://[2001:db8:abcd:0012::]/64", "http://[2001:db8:abcd:12::1]", True), + ("all://[2001:db8:abcd:0012::]/64", "http://[2001:db8:abcd:13::1]:8080", False), ], ) def test_url_matches(pattern, url, expected):