Skip to content

Commit 7a64502

Browse files
hugovkplamut
authored andcommitted
fix: replace unsafe six.PY3 with PY2 for better future compatibility with Python 4 (googleapis#10081)
* fix: fix for Python 4: replace unsafe six.PY3 with PY2 * Fix wording
1 parent c71d5f8 commit 7a64502

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

logging/tests/unit/handlers/test__helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get(self):
7777
self.response.out.write(json.dumps(trace_id))
7878

7979

80-
@unittest.skipIf(six.PY3, "webapp2 is Python 2 only")
80+
@unittest.skipIf(not six.PY2, "webapp2 is Python 2 only")
8181
class Test_get_trace_id_from_webapp2(unittest.TestCase):
8282
@staticmethod
8383
def create_app():

pubsub/synth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@
127127
"google/cloud/pubsub_v1/gapic/publisher_client.py",
128128
"class PublisherClient",
129129
"""# TODO: remove conditional import after Python 2 support is dropped
130-
if six.PY3:
131-
from collections.abc import Mapping
132-
else:
130+
if six.PY2:
133131
from collections import Mapping
132+
else:
133+
from collections.abc import Mapping
134134
135135
136136
def _merge_dict(d1, d2):

storage/google/cloud/storage/batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ def _prepare_batch_request(self):
214214
timeout = _timeout
215215

216216
# The `email` package expects to deal with "native" strings
217-
if six.PY3: # pragma: NO COVER Python3
218-
buf = io.StringIO()
219-
else:
217+
if six.PY2: # pragma: NO COVER Python3
220218
buf = io.BytesIO()
219+
else:
220+
buf = io.StringIO()
221221
generator = Generator(buf, False, 0)
222222
generator.flatten(multi)
223223
payload = buf.getvalue()

storage/tests/unit/test__signing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def test_w_expiration_int(self):
6969
self.assertEqual(self._call_fut(123), 123)
7070

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

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

0 commit comments

Comments
 (0)