diff --git a/owners.py b/owners.py index f46fef284..7fa69e365 100644 --- a/owners.py +++ b/owners.py @@ -77,7 +77,7 @@ GLOBAL_STATUS = '*' def _assert_is_collection(obj): - assert not isinstance(obj, basestring) + assert not isinstance(obj, str) # Module 'collections' has no 'Iterable' member # pylint: disable=no-member if hasattr(collections, 'Iterable') and hasattr(collections, 'Sized'): @@ -508,7 +508,7 @@ class Database(object): # Now that we've used `owner` and covered all their dirs, remove them # from consideration. del all_possible_owners[owner] - for o, dirs in all_possible_owners.items(): + for o, dirs in list(all_possible_owners.items()): new_dirs = [(d, dist) for (d, dist) in dirs if d not in dirs_to_remove] if not new_dirs: del all_possible_owners[o] @@ -606,9 +606,9 @@ class Database(object): dirs) # Return the lowest cost owner. In the case of a tie, pick one randomly. lowest_cost = min(total_costs_by_owner.values()) - lowest_cost_owners = filter( - lambda owner: total_costs_by_owner[owner] == lowest_cost, - total_costs_by_owner) + lowest_cost_owners = [ + owner for owner, cost in total_costs_by_owner.items() + if cost == lowest_cost] return random.Random().choice(lowest_cost_owners) def owners_rooted_at_file(self, filename): diff --git a/testing_support/filesystem_mock.py b/testing_support/filesystem_mock.py index 36a258e2d..47c86e32a 100644 --- a/testing_support/filesystem_mock.py +++ b/testing_support/filesystem_mock.py @@ -6,7 +6,12 @@ import errno import fnmatch import os import re -import StringIO +import sys + +if sys.version_info.major == 2: + from StringIO import StringIO +else: + from io import StringIO def _RaiseNotFound(path): @@ -63,7 +68,7 @@ class MockFileSystem(object): # We need to use a copy of the keys here in order to avoid switching # to a different thread and potentially modifying the dict in # mid-iteration. - files = self.files.keys()[:] + files = list(self.files.keys())[:] return any(f.startswith(path) for f in files) def join(self, *comps): @@ -75,7 +80,7 @@ class MockFileSystem(object): return fnmatch.filter(self.files.keys(), path) def open_for_reading(self, path): - return StringIO.StringIO(self.read_binary_file(path)) + return StringIO(self.read_binary_file(path)) def normpath(self, path): # This is not a complete implementation of normpath. Only covers what we diff --git a/tests/owners_finder_test.py b/tests/owners_finder_test.py index 5804d4f46..6ebf23517 100755 --- a/tests/owners_finder_test.py +++ b/tests/owners_finder_test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env vpython3 # Copyright 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. diff --git a/tests/owners_unittest.py b/tests/owners_unittest.py index b8c008639..b1f4ee4b5 100755 --- a/tests/owners_unittest.py +++ b/tests/owners_unittest.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env vpython3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file.