From 00585b35b2134a80773d18ce5dbfb6586fc55bda Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Tue, 6 Apr 2021 12:44:58 +0300 Subject: [PATCH] Simplified GFG by removing some unneeded `else`s --- https_everywhere/_rules.py | 18 +++++++++--------- https_everywhere/_unregex.py | 8 ++++---- https_everywhere/_util.py | 4 ++-- https_everywhere/adapter.py | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/https_everywhere/_rules.py b/https_everywhere/_rules.py index f5f33f3..0cea38e 100644 --- a/https_everywhere/_rules.py +++ b/https_everywhere/_rules.py @@ -238,15 +238,15 @@ def _is_rule_only_force_https(ruleset, rule): ) ) return False - else: - # There are five of these, and the pattern and replacement have the same path, so can easily be - # reduced by adding an exclusion as inverse regex of the path in the rule - logger.info( - "{} matches {} but has a path, and is not reducible yet".format( - targets, rule.pattern - ) + + # There are five of these, and the pattern and replacement have the same path, so can easily be + # reduced by adding an exclusion as inverse regex of the path in the rule + logger.info( + "{} matches {} but has a path, and is not reducible yet".format( + targets, rule.pattern ) - return False + ) + return False else: # pragma: no cover logger.debug("{} not matches targets {}".format(rule.pattern, targets)) assert rule.pattern_targets[0] in targets @@ -444,7 +444,7 @@ def _reduce_ruleset(ruleset): # ~500 cases ruleset._rules = REMOVE_WWW_and_FORCE_HTTPS_RULES return True - elif rule.add_www: + if rule.add_www: # ~1100 cases ruleset._rules = ADD_WWW_and_FORCE_HTTPS_RULES return True diff --git a/https_everywhere/_unregex.py b/https_everywhere/_unregex.py index c69e141..ed8d1d5 100644 --- a/https_everywhere/_unregex.py +++ b/https_everywhere/_unregex.py @@ -63,8 +63,8 @@ def expand_pattern(pattern, max_count=100): s, sorted(set(p.host) - valid_host_char) ) ) - else: - return [p.host] + + return [p.host] except urllib3.exceptions.LocationParseError: # pragma: no cover # TODO: build test case for this pass @@ -130,11 +130,11 @@ def split_regex(pattern, at, remainer=False): found = True del pattern[i] continue - elif not found and tok == sre_parse.IN and (sre_parse.LITERAL, ord(at)) in val: + if not found and tok == sre_parse.IN and (sre_parse.LITERAL, ord(at)) in val: found = True del pattern[i] continue - elif not found and tok == sre_parse.MAX_REPEAT: + if not found and tok == sre_parse.MAX_REPEAT: val = val[2] if (sre_parse.LITERAL, ord(at)) in val: found = True diff --git a/https_everywhere/_util.py b/https_everywhere/_util.py index 23b4705..ddcf621 100644 --- a/https_everywhere/_util.py +++ b/https_everywhere/_util.py @@ -5,8 +5,8 @@ def _reverse_host(host, trailing_dot=True): rv = ".".join(reversed(host.split("."))) if trailing_dot: return rv + "." - else: - return rv + + return rv def _check_in(domains, hostname): diff --git a/https_everywhere/adapter.py b/https_everywhere/adapter.py index 4d16a5c..0f5b6be 100644 --- a/https_everywhere/adapter.py +++ b/https_everywhere/adapter.py @@ -254,7 +254,7 @@ def _follow_redirects_on_http(self, url): if self._prevent_https(tail): return "http://" + tail return response - elif location.startswith("http://"): + if location.startswith("http://"): previous_url = current_url url = location else: @@ -285,7 +285,7 @@ def send(self, request, *args, **kwargs): "upgrading {} to https with {}".format(url, redirect.url) ) return redirect - elif redirect != url: + if redirect != url: if redirect.startswith("http://"): tail = url[7:] else: