GeezerVison is showing github.com — fix: replace unsafe six.PY3 with PY2 for better future compatibility with Python 4 by hugovk · Pull Request #10081 · googleapis/google-cloud-python
Conversation
hugovk
commented
Jan 9, 2020
•
edited by plamut
Loading
Uh oh!
There was an error while loading. Please reload this page.
Fixes #10158.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [trivial] Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
(edit by @plamut: opened the issue for better traceability)
- Ensure the tests and linter pass
- Code coverage does not decrease (if any source code was changed)
- [n/a] Appropriate docs were updated (if necessary)
We don't yet know if 3.10 or 4.0 will follow Python 3.9, but whichever it is, it will probably happen in 2020 when Python 3.9 reaches beta and work begins on Python 3.9+1.
There's some code which uses six.PY3:
if six.PY3:
print("Python 3+ code")
else:
print "Python 2 code"
Where:
PY3 = sys.version_info[0] == 3
When run on Python 4, this will run the Python 2 code!
Instead, use six.PY2.
Found using https://github.com/asottile/flake8-2020.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
plamut
left a comment
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing for "is (not) PY2" instead of "is (not) PY3" is indeed more robust, thanks for catching that!
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
plamut
left a comment
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(speaking for the PubSub library)
The change is good, but needs to be made in the synth file that is used to generate the file changed here.
The changes to the files in other libraries are fine, as those files are not auto-generated (AFAIK).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
plamut
changed the title
Fix for Python 4: replace unsafe six.PY3 with PY2
fix: replace unsafe six.PY3 with PY2 for better future compatibility with Python 4
Jan 9, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one final remark.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @hugovk!
Will delay merging for a day or so if anybody else wants to review it.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
hugovk reacted with thumbs up emoji
plamut
commented
Jan 10, 2020
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
The test failures are not related, also happen on master. Investigating.
Update: At least for logging, the test failure is caused by an out-of-date assertion - an optional timeout was added to core recently. Will be fixed in #10087.
Update 2: The Storage failures also seem to be a regression, will submit a fix for that, too (edit: submitted).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jan 29, 2020
parthea
pushed a commit
that referenced
this pull request
Nov 24, 2025
…with Python 4 (#10081)
* fix: fix for Python 4: replace unsafe six.PY3 with PY2
* Fix wording
parthea
pushed a commit
that referenced
this pull request
Mar 2, 2026
…with Python 4 (#10081)
* fix: fix for Python 4: replace unsafe six.PY3 with PY2
* Fix wording
parthea
pushed a commit
that referenced
this pull request
Mar 9, 2026
…with Python 4 (#10081)
* fix: fix for Python 4: replace unsafe six.PY3 with PY2
* Fix wording
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
api: logging
Issues related to the Cloud Logging API.
api: pubsub
Issues related to the Pub/Sub API.
api: storage
Issues related to the Cloud Storage API.
cla: yes
This human has signed the Contributor License Agreement.
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|