-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Python 2.7 support and six.py #11418
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
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.
Thank you very much for your contribution!!
@@ -613,17 +612,17 @@ def _is_prefix_empty(self, tr, prefix): | |||
|
|||
def _to_unicode_path(path): | |||
if isinstance(path, bytes): | |||
path = six.text_type(path) | |||
path = str(path) |
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.
I would guess this may not work as bytes
are not encoded in Python while str
is encoded by utf-8 by default. I think it might be better to do path.decode()
to introduce a conversion.
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.
Hmm, happy to change it, but wouldn't they be the same? Both str(path)
or path.decode()
would return a unicode string in Python 3, no? 🤔
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.
Well, I think they are somewhat different, I just tried it on Python 3.12
Python 3.12.0 (main, Nov 9 2023, 17:03:26) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> s=b"1234"
>>> print(s)
b'1234'
>>> type(s)
<class 'bytes'>
>>> t=str(s)
>>> print(t)
b'1234'
>>> type(t)
<class 'str'>
>>> print(f"{t}")
b'1234'
>>> print(f"[{t}]")
[b'1234']
>>>
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.
Oh I see, you are absolutely right. Continuing on your answer,
>>> s.decode() == str(s)
False
But for str
to decode bytes
, encoding
must be passed:
>>> s.decode() == str(s, 'utf-8')
True
Also validated with the docs:
If neither encoding nor errors is given, str(object) returns
type(object).__str__(object)
, which is the “informal” or nicely printable string representation of object. For string objects, this is the string itself. If object does not have a__str__()
method, then str() falls back to returning repr(object).
https://docs.python.org/3/library/stdtypes.html#str
TIL, and I will make the change.
May you please also have a look at the comment for _to_unicode_path
?
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.
Yeah, Python has plenty of pitfalls but better than C++, while I would suggest we move to Rust sometime since things would be more explicit -- in Rust str must be encoded and bytes are simply [u8]; so you can never simply [u8].to_str() without checking the encoding.
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.
Yeah ^-^ Also TIL, python -b
to catch this. Apparently, it is a thing, and there's also python -bb
to treat these as errors.
Let's check for the binding correctness in the CI after you changed the code. We have plenty of tests to make sure we do not break things, but still, not enough. |
4485534
to
dc5510a
Compare
Result of foundationdb-pr-clang-ide on Linux CentOS 7
|
Result of foundationdb-pr-clang on Linux CentOS 7
|
Result of foundationdb-pr on Linux CentOS 7
|
Hi there, please let me know if there's anything wrong. I see some tests are failing but couldn't be sure if they are related - I see they fail in some other PRs as well. |
I saw some changes for bindingtester, so @xis19 can you make sure bindingtester can still pass joshua test? |
Result of foundationdb-pr-clang-ide on Linux CentOS 7
|
Result of foundationdb-pr-macos-m1 on macOS Ventura 13.x
|
Result of foundationdb-pr-cluster-tests on Linux CentOS 7
|
Result of foundationdb-pr-clang on Linux CentOS 7
|
Result of foundationdb-pr on Linux CentOS 7
|
Result of foundationdb-pr-macos on macOS Ventura 13.x
|
Result of foundationdb-pr-clang-arm on Linux CentOS 7
|
dc5510a
to
4cf353c
Compare
Thanks for the reminder, @sepeth. I don't have enough context on this PR, I'll see if @xis19 can review this otherwise I can find some cycles to review. |
Result of foundationdb-pr-clang-ide on Linux CentOS 7
|
Result of foundationdb-pr-macos-m1 on macOS Ventura 13.x
|
Result of foundationdb-pr-macos on macOS Ventura 13.x
|
Result of foundationdb-pr-clang-arm on Linux CentOS 7
|
Result of foundationdb-pr-cluster-tests on Linux CentOS 7
|
Result of foundationdb-pr-clang on Linux CentOS 7
|
Result of foundationdb-pr on Linux CentOS 7
|
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
Hello,
This is my first contribution to FoundationDB. I thought I could start from something simple ^-^
This change removes Python 2.7 support and six.py (resolves #11328 and #11329). Most of it is straightforward, such as
six.text_type -> str
,six.integer_types -> int
. OTOH, decisions I made:int2byte
as it is nicer to read thanstruct.Struct(">B").pack
, and it was used many times.I first tested with the class scheduling examples in the tutorial and validated that
fdb.__path__
was pointing to the fdb that I modified and installed.Then, I tested via
run_tester_loop.sh
&bindingtester.py
. This took a bit of time and required some fiddling with sources. But eventually, I got it running, and all python tests have passed. A few issues I had to overcome:bindingtester.py
is prepending a path tosys.path
, which didn't allow me to runrun_tester_loop.sh
from the source dir.bindingtester
weren't copied/built into the build tree (due to a check inbindingtester/CMakeLists.txt
). I am not sure about the implications of enabling this, but it would be nice ifbindingtester
is easier to run in case changes made to bindings. I didn't want to make assumptions and changes about this, and wanted to keep this solely for removing Python 2.7 support, but I am happy to look into this in another PR (and happy to hear your suggestions).Code-Reviewer Section
The general pull request guidelines can be found here.
Please check each of the following things and check all boxes before accepting a PR.
For Release-Branches
If this PR is made against a release-branch, please also check the following:
release-branch
ormain
if this is the youngest branch)