-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-2001 Fix warnings emitted by Python 3.8 #428
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
Conversation
Fix DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats Fix DeprecationWarning: isAlive() is deprecated, use is_alive() instead Fix SyntaxWarning: invalid escape sequence Test Python 3.8 on Travis
@@ -20,6 +20,7 @@ | |||
* should be used to speed up BSON encoding and decoding. | |||
*/ | |||
|
|||
#define PY_SSIZE_T_CLEAN |
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.
See python/cpython@0895793 and https://docs.python.org/3.8/c-api/arg.html#strings-and-buffers for an explanation of the PY_SSIZE_T_CLEAN changes.
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.
PEP 353 -- Using ssize_t as the index type is also worth a read. The "Conversion guidelines" section in particular. I've gone ahead and fixed the conversion warnings by using the 3 option: "otherwise, check whether the value fits an int, and raise a ValueError if it doesn't."
I still need to fix these test failures on Windows:
And these build warnings:
Python 2.7 on macOS:
|
result = Py_BuildValue("s#", buffer_get_buffer(buffer), | ||
buffer_get_position(buffer)); | ||
#endif | ||
result = Py_BuildValue(BYTES_FORMAT_STRING, buffer_get_buffer(buffer), |
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 guess we don't need BYTES_FORMAT_STRING anymore. Just use y#?
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.
We still need to use s#
on Python 2.7 because y#
does not exist there: https://docs.python.org/2.7/c-api/arg.html
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've fixed the warnings in the latest commit. I considered adding a test for a very large collection name but it ends up taking 10-20 seconds to run. This is the error with the C extensions:
>>> client.db['s'*(1 + 2**31)].insert_one({})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 698, in insert_one
session=session),
...
File "/Users/shane/git/mongo-python-driver/pymongo/message.py", line 706, in _op_msg
flags, command, identifier, docs, check_keys, opts)
bson.errors.InvalidStringData: String length must be <= 2147483647
This is the error without the C extensions:
>>> client.db['s'*(1 + 2**31)].insert_one({})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 698, in insert_one
session=session),
...
File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 812, in _name_value_to_bson
return _ENCODERS[type(value)](name, value, check_keys, opts)
File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 622, in _encode_text
return b"\x02" + name + _PACK_INT(len(value) + 1) + value + b"\x00"
struct.error: 'i' format requires -2147483648 <= number <= 2147483647
Maybe we should also add some Database/Collection level validation that names aren't longer than maxBsonObjectSize?
result = Py_BuildValue("s#", buffer_get_buffer(buffer), | ||
buffer_get_position(buffer)); | ||
#endif | ||
result = Py_BuildValue(BYTES_FORMAT_STRING, buffer_get_buffer(buffer), |
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.
We still need to use s#
on Python 2.7 because y#
does not exist there: https://docs.python.org/2.7/c-api/arg.html
@@ -20,6 +20,7 @@ | |||
* should be used to speed up BSON encoding and decoding. | |||
*/ | |||
|
|||
#define PY_SSIZE_T_CLEAN |
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.
PEP 353 -- Using ssize_t as the index type is also worth a read. The "Conversion guidelines" section in particular. I've gone ahead and fixed the conversion warnings by using the 3 option: "otherwise, check whether the value fits an int, and raise a ValueError if it doesn't."
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!
This change will avoid masking accidental implcit 64->32 conversions in future code that calls buffer_write_bytes.
Fixed the failures by properly exporting |
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
Fix DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats
Fix DeprecationWarning: isAlive() is deprecated, use is_alive() instead
Fix SyntaxWarning: invalid escape sequence
Test Python 3.8 on Travis
https://jira.mongodb.org/browse/PYTHON-2001