-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Binary expects data to be bytes #399
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
I believe the text you change refers to Python 2. IMO a better change would be to mention each version and its type explicitly: |
@salty-horse is correct. PyMongo used to support Python versions all the way back to 2.3. bytes was new in Python 2.6 (and just an alias for str in 2.6 and 2.7). We've dropped support for Python 2.6 in master. It's probably OK to change the string this way, but also get rid of the redundant "(:class: |
Please don't remove documentation for Python 2 from the library until support is dropped completely. People are still using it. |
This wouldn't remove Python 2 docs. bytes exists in Python 2. It's an alias for str. |
It's an alias for the sake of easing Python 3 migrations/compatibility. Documentation relating to the Python 2 type Making this line only mention |
If this is intended to refer to Python 2, which was not actually clear to me, I would suggest choosing language in the docs that makes that clear. |
I don't understand the rush to favor one Python version over another, when the docs can be explicit about both with little effort. Compare with a similar note in
|
We are not favoring one version over another and we are still documenting both versions. However, I do think it makes sense to refer to the Python 3 types first and Python 2 types second. Python 3 is the future. Seasoned python developers who write both 3 and 2 will understand the documentation regardless of which version appears first but I think referring to Python 3 first will help newer developers who only know Python 3. So I think changing from |
On a different note (and part of my motivation for looking at this part of the documentation), we didn't find this to be exactly true. When saving a |
Please let me know if anything else is needed :) |
Anything else needed here? |
Thanks for the fix @jakirkham.
Unfortunately, we cannot return a Consider that if we did decode to >>> from bson import BSON
>>> from bson.binary import Binary
>>>
>>> encoded = BSON.encode({'binary': Binary(b'my_bytes')})
>>> decoded = encoded.decode()
>>> decoded
{u'binary': 'my_bytes'} # Decoded Binary subtype 0 as "bytes" in Python 2
>>> # This might seem okay until we try to encode this document again:
>>> encoded = BSON.encode(decoded)
>>> decoded = encoded.decode()
>>> decoded
{u'binary': u'my_bytes'} # Notice the "u" prefix?
>>> # 'my_bytes' is now a unicode because we encode `str` to BSON's UTF-8 string type and then decode to Python 2 unicode. |
(cherry picked from commit 5950abf)
No description provided.