PYTHON-5757 Deprecate Python 2 methods in SON#2732
PYTHON-5757 Deprecate Python 2 methods in SON#2732aclark4life merged 2 commits intomongodb:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR deprecates legacy Python 2 compatibility methods on bson.son.SON by emitting DeprecationWarnings and updates documentation/tests to steer users toward idiomatic Python 3 usage.
Changes:
- Added
DeprecationWarningemissions forSON.has_key,SON.iterkeys, andSON.itervalues. - Updated SON tests to stop using
has_keyand use theinoperator instead. - Documented the deprecations and planned removal (PyMongo 5.0) in the changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
bson/son.py |
Adds deprecation warnings to Python 2-era SON methods. |
test/test_son.py |
Updates tests to use Python 3 membership syntax rather than has_key. |
doc/changelog.rst |
Notes the SON method deprecations and planned removal timeline. |
test/test_son.py
Outdated
| def test_contains_has(self): | ||
| """has_key and __contains__""" | ||
| """key in SON and __contains__""" |
doc/changelog.rst
Outdated
| deprecated in favor of the standard dictionary methods ``in``, ``keys``, and | ||
| ``values`` respectively. |
test/test_son.py
Outdated
| self.assertTrue(2 in test_son, "'in' operator failed for key 2") | ||
| self.assertFalse(22 in test_son, "'in' operator succeeded when it shouldn't") |
There was a problem hiding this comment.
| self.assertTrue(2 in test_son, "'in' operator failed for key 2") | |
| self.assertFalse(22 in test_son, "'in' operator succeeded when it shouldn't") |
The above line of assertIn already runs that validation.
There was a problem hiding this comment.
Different values. Line 153 is checking 2. Line 154 is checking 22.
There was a problem hiding this comment.
I think @Jibola was saying that like 153 does the same thing as line 151 and line 154 is the same as line 152. (and if so, I agree lol)
There was a problem hiding this comment.
Ah! Good catch thanks
d48542c to
89af051
Compare
bson/son.py contains three methods that were added for Python 2 compatibility but are no longer needed
89af051 to
554904d
Compare
|
@sleepyStick Sorry, I rebased can you approve again? Thanks |
|
And … sorry I guess I needed @Jibola ! Thanks all |
bson/son.py contains three methods that were added for Python 2 compatibility but are no longer needed
INTPYTHON-5757
Changes in this PR
bson/son.py contains three methods that were added for Python 2 compatibility but are no longer needed
Test Plan
Updated tests to use new syntax.
Checklist
Checklist for Author
Checklist for Reviewer