python: Modernize legacy Python 2 syntax with pyupgrade.

Generated by `pyupgrade --py3-plus --keep-percent-format` on all our
Python code except `zthumbor` and `zulip-ec2-configure-interfaces`,
followed by manual indentation fixes.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-04-09 12:51:58 -07:00
committed by Tim Abbott
parent fff2d3958a
commit c734bbd95d
567 changed files with 1877 additions and 2564 deletions

View File

@@ -159,7 +159,7 @@ class TitleMatchRegexAllowException(LineRule):
regex = self.options['regex'].value
pattern = re.compile(regex, re.UNICODE)
if not pattern.search(title) and not title.startswith("Revert \""):
violation_msg = u"Title does not match regex ({0})".format(regex)
violation_msg = "Title does not match regex ({})".format(regex)
return [RuleViolation(self.id, violation_msg, title)]
return []

View File

@@ -119,7 +119,7 @@ def make_dot_file(graph):
def test():
# type: () -> None
graph = Graph(set([
graph = Graph({
('x', 'a'),
('a', 'b'),
('b', 'c'),
@@ -128,7 +128,7 @@ def test():
('d', 'e'),
('e', 'f'),
('e', 'g'),
]))
})
graph.remove_exterior_nodes()
s = make_dot_file(graph)

View File

@@ -193,7 +193,7 @@ def build_id_dict(templates):
template_id_dict = defaultdict(list) # type: (Dict[str, List[str]])
for fn in templates:
with open(fn, 'r') as f:
with open(fn) as f:
text = f.read()
list_tags = tokenize(text)

View File

@@ -7,7 +7,7 @@ def show_all_branches(fns):
# type: (List[str]) -> None
for fn in fns:
print(fn)
with open(fn, 'r') as f:
with open(fn) as f:
text = f.read()
branches = html_branches(text, fn=fn)
for branch in branches:
@@ -26,7 +26,7 @@ class Grepper:
all_branches = [] # type: List[HtmlTreeBranch]
for fn in fns:
with open(fn, 'r') as f:
with open(fn) as f:
text = f.read()
branches = html_branches(text, fn=fn)
all_branches += branches

View File

@@ -193,7 +193,7 @@ def pretty_print_html(html, num_spaces=4):
def validate_indent_html(fn, fix):
# type: (str, bool) -> int
with open(fn, 'r') as f:
with open(fn) as f:
html = f.read()
phtml = pretty_print_html(html)
if not html.split('\n') == phtml.split('\n'):

View File

@@ -41,7 +41,7 @@ def setup_shell_profile(shell_profile):
def write_command(command):
# type: (str) -> None
if os.path.exists(shell_profile_path):
with open(shell_profile_path, 'r') as shell_profile_file:
with open(shell_profile_path) as shell_profile_file:
lines = [line.strip() for line in shell_profile_file.readlines()]
if command not in lines:
with open(shell_profile_path, 'a+') as shell_profile_file:
@@ -77,7 +77,7 @@ def setup_bash_profile() -> None:
if os.path.exists(DOT_PROFILE):
try:
with open(BASH_PROFILE, "r") as f:
with open(BASH_PROFILE) as f:
profile_contents = f.read()
if profile_contents == OLD_PROFILE_TEXT:
os.unlink(BASH_PROFILE)

View File

@@ -214,7 +214,7 @@ def validate(fn=None, text=None, check_indent=True):
fn = '<in memory file>'
if text is None:
with open(fn, 'r') as f:
with open(fn) as f:
text = f.read()
tokens = tokenize(text)

View File

@@ -56,7 +56,7 @@ def get_provisioning_status():
# their own dependencies and not running provision.
return True, None
with open(version_file, 'r') as f:
with open(version_file) as f:
version = f.read().strip()
# Normal path for people that provision--we're all good!