From 14014571a5398a5d5514752c2e5032d681550f07 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 9 Jan 2020 13:33:16 +0200 Subject: [PATCH 1/2] fix: fix for Python 4: replace unsafe six.PY3 with PY2 --- logging/tests/unit/handlers/test__helpers.py | 2 +- pubsub/synth.py | 6 +++--- storage/google/cloud/storage/batch.py | 6 +++--- storage/tests/unit/test__signing.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/logging/tests/unit/handlers/test__helpers.py b/logging/tests/unit/handlers/test__helpers.py index b5ba26fd17a7..702015961771 100644 --- a/logging/tests/unit/handlers/test__helpers.py +++ b/logging/tests/unit/handlers/test__helpers.py @@ -77,7 +77,7 @@ def get(self): self.response.out.write(json.dumps(trace_id)) -@unittest.skipIf(six.PY3, "webapp2 is Python 2 only") +@unittest.skipIf(not six.PY2, "webapp2 is Python 2 only") class Test_get_trace_id_from_webapp2(unittest.TestCase): @staticmethod def create_app(): diff --git a/pubsub/synth.py b/pubsub/synth.py index a65bf2bf4f56..88ac4a8d4f7e 100644 --- a/pubsub/synth.py +++ b/pubsub/synth.py @@ -127,10 +127,10 @@ "google/cloud/pubsub_v1/gapic/publisher_client.py", "class PublisherClient", """# TODO: remove conditional import after Python 2 support is dropped -if six.PY3: - from collections.abc import Mapping -else: +if six.PY2: from collections import Mapping +else: + from collections.abc import Mapping def _merge_dict(d1, d2): diff --git a/storage/google/cloud/storage/batch.py b/storage/google/cloud/storage/batch.py index f71230a89cea..92f1a18d1c1d 100644 --- a/storage/google/cloud/storage/batch.py +++ b/storage/google/cloud/storage/batch.py @@ -214,10 +214,10 @@ def _prepare_batch_request(self): timeout = _timeout # The `email` package expects to deal with "native" strings - if six.PY3: # pragma: NO COVER Python3 - buf = io.StringIO() - else: + if six.PY2: # pragma: NO COVER Python3 buf = io.BytesIO() + else: + buf = io.StringIO() generator = Generator(buf, False, 0) generator.flatten(multi) payload = buf.getvalue() diff --git a/storage/tests/unit/test__signing.py b/storage/tests/unit/test__signing.py index f2609d63e428..340c6acdd03a 100644 --- a/storage/tests/unit/test__signing.py +++ b/storage/tests/unit/test__signing.py @@ -69,7 +69,7 @@ def test_w_expiration_int(self): self.assertEqual(self._call_fut(123), 123) def test_w_expiration_long(self): - if six.PY3: + if not six.PY2: raise unittest.SkipTest("No long on Python 3") self.assertEqual(self._call_fut(long(123)), 123) # noqa: F821 From 09c70b6b8c632dd3413ea2824fc70872f18589ff Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 9 Jan 2020 19:58:55 +0200 Subject: [PATCH 2/2] Fix wording --- storage/tests/unit/test__signing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/tests/unit/test__signing.py b/storage/tests/unit/test__signing.py index 340c6acdd03a..bce709201dc4 100644 --- a/storage/tests/unit/test__signing.py +++ b/storage/tests/unit/test__signing.py @@ -70,7 +70,7 @@ def test_w_expiration_int(self): def test_w_expiration_long(self): if not six.PY2: - raise unittest.SkipTest("No long on Python 3") + raise unittest.SkipTest("No long on Python 3+") self.assertEqual(self._call_fut(long(123)), 123) # noqa: F821