diff --git a/git_config.py b/git_config.py index 87ed9765..971066ef 100644 --- a/git_config.py +++ b/git_config.py @@ -15,7 +15,7 @@ import contextlib import datetime import errno -from http.client import HTTPException +import http.client import json import os import re @@ -650,7 +650,7 @@ class Remote(object): raise UploadError("%s: %s" % (self.review, str(e))) except urllib.error.URLError as e: raise UploadError("%s: %s" % (self.review, str(e))) - except HTTPException as e: + except http.client.HTTPException as e: raise UploadError( "%s: %s" % (self.review, e.__class__.__name__) ) diff --git a/release/update_manpages.py b/release/update_manpages.py index cd2acc01..cb687245 100644 --- a/release/update_manpages.py +++ b/release/update_manpages.py @@ -18,8 +18,8 @@ Most code lives in this module so it can be unittested. """ from pathlib import Path -from functools import partial import argparse +import functools import multiprocessing import os import re @@ -112,7 +112,9 @@ def main(argv): # Run all cmd in parallel, and wait for them to finish. with multiprocessing.Pool() as pool: - pool.map(partial(worker, cwd=tempdir, check=True), cmdlist) + pool.map( + functools.partial(worker, cwd=tempdir, check=True), cmdlist + ) for tmp_path in MANDIR.glob("*.1.tmp"): path = tmp_path.parent / tmp_path.stem diff --git a/repo_trace.py b/repo_trace.py index 49462174..01beaf8e 100644 --- a/repo_trace.py +++ b/repo_trace.py @@ -20,11 +20,11 @@ Temporary: Tracing is always on. Set `REPO_TRACE=0` to turn off. To also include trace outputs in stderr do `repo --trace_to_stderr ...` """ +import contextlib import sys import os import time import tempfile -from contextlib import ContextDecorator import platform_utils @@ -68,7 +68,7 @@ def _SetTraceFile(quiet): _TRACE_FILE = _GetTraceFile(quiet) -class Trace(ContextDecorator): +class Trace(contextlib.ContextDecorator): """Used to capture and save git traces.""" def _time(self): diff --git a/subcmds/abandon.py b/subcmds/abandon.py index 896b348f..1499c75e 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from collections import defaultdict +import collections import functools import itertools import sys @@ -88,8 +88,8 @@ It is equivalent to "git branch -D ". def Execute(self, opt, args): nb = args[0].split() - err = defaultdict(list) - success = defaultdict(list) + err = collections.defaultdict(list) + success = collections.defaultdict(list) aggregate_errors = [] all_projects = self.GetProjects( args[1:], all_manifests=not opt.this_manifest_only diff --git a/subcmds/selfupdate.py b/subcmds/selfupdate.py index 00376b66..983fd630 100644 --- a/subcmds/selfupdate.py +++ b/subcmds/selfupdate.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from optparse import SUPPRESS_HELP +import optparse import sys from command import Command, MirrorSafeCommand @@ -52,7 +52,7 @@ need to be performed by an end-user. "--repo-upgraded", dest="repo_upgraded", action="store_true", - help=SUPPRESS_HELP, + help=optparse.SUPPRESS_HELP, ) def Execute(self, opt, args): diff --git a/subcmds/sync.py b/subcmds/sync.py index 159771eb..74bc4557 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -19,7 +19,7 @@ import io import json import multiprocessing import netrc -from optparse import SUPPRESS_HELP +import optparse import os import socket import sys @@ -481,7 +481,7 @@ later is required to fix a server side protocol bug. "--repo-upgraded", dest="repo_upgraded", action="store_true", - help=SUPPRESS_HELP, + help=optparse.SUPPRESS_HELP, ) def _GetBranch(self, manifest_project): diff --git a/tests/test_repo_logging.py b/tests/test_repo_logging.py index ba8a9a9e..5402a90b 100644 --- a/tests/test_repo_logging.py +++ b/tests/test_repo_logging.py @@ -14,7 +14,7 @@ """Unit test for repo_logging module.""" import unittest -from unittest.mock import MagicMock +from unittest import mock from repo_logging import RepoLogger @@ -30,7 +30,7 @@ class TestRepoLogger(unittest.TestCase): nonlocal result result = log.getMessage() - mock_out = MagicMock() + mock_out = mock.MagicMock() mock_out.level = 0 mock_out.handle = mock_handler logger.addHandler(mock_out) @@ -49,7 +49,7 @@ class TestRepoLogger(unittest.TestCase): nonlocal result result = log.getMessage() - mock_out = MagicMock() + mock_out = mock.MagicMock() mock_out.level = 0 mock_out.handle = mock_handler logger.addHandler(mock_out) @@ -88,7 +88,7 @@ class TestRepoLogger(unittest.TestCase): nonlocal result result.append(log.getMessage()) - mock_out = MagicMock() + mock_out = mock.MagicMock() mock_out.level = 0 mock_out.handle = mock_handler logger.addHandler(mock_out) diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index 4e8263b2..ef4dce10 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py @@ -14,7 +14,7 @@ """Unittests for the wrapper.py module.""" -from io import StringIO +import io import os import re import sys @@ -47,8 +47,10 @@ class RepoWrapperUnitTest(RepoWrapperTestCase): def test_version(self): """Make sure _Version works.""" with self.assertRaises(SystemExit) as e: - with mock.patch("sys.stdout", new_callable=StringIO) as stdout: - with mock.patch("sys.stderr", new_callable=StringIO) as stderr: + with mock.patch("sys.stdout", new_callable=io.StringIO) as stdout: + with mock.patch( + "sys.stderr", new_callable=io.StringIO + ) as stderr: self.wrapper._Version() self.assertEqual(0, e.exception.code) self.assertEqual("", stderr.getvalue())