Skip to content

Commit

Permalink
fix: replace unsafe six.PY3 with PY2 for better future compatibility …
Browse files Browse the repository at this point in the history
…with Python 4 (#10081)

* fix: fix for Python 4: replace unsafe six.PY3 with PY2

* Fix wording
  • Loading branch information
hugovk authored and plamut committed Jan 15, 2020
1 parent c71d5f8 commit 7a64502
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion logging/tests/unit/handlers/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
6 changes: 3 additions & 3 deletions pubsub/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions storage/google/cloud/storage/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions storage/tests/unit/test__signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def test_w_expiration_int(self):
self.assertEqual(self._call_fut(123), 123)

def test_w_expiration_long(self):
if six.PY3:
raise unittest.SkipTest("No long on Python 3")
if not six.PY2:
raise unittest.SkipTest("No long on Python 3+")

self.assertEqual(self._call_fut(long(123)), 123) # noqa: F821

Expand Down

0 comments on commit 7a64502

Please sign in to comment.