Skip to content

PYTHON-2057 Make 'name' a required argument for DriverInfo class #718

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

Merged
merged 4 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Breaking Changes in 4.0
- Removed :class:`bson.binary.UUIDLegacy`.
- The "tls" install extra is no longer necessary or supported and will be
ignored by pip.
- ``name`` is now a required argument for the :class:`pymongo.driver_info.DriverInfo` class.

Notable improvements
....................
Expand Down
7 changes: 7 additions & 0 deletions doc/migrate-to-pymongo4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -725,3 +725,10 @@ pymongo.message helpers are removed
Removed :meth:`pymongo.message.delete`, :meth:`pymongo.message.get_more`,
:meth:`pymongo.message.insert`, :meth:`pymongo.message.kill_cursors`,
:meth:`pymongo.message.query`, and :meth:`pymongo.message.update`.


Name is a required argument for pymongo.driver_info.DriverInfo
..............................................................

``name`` is now a required argument for the :class:`pymongo.driver_info.DriverInfo` class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there needs to be a blank line after the ....... header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


2 changes: 1 addition & 1 deletion pymongo/driver_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DriverInfo(namedtuple('DriverInfo', ['name', 'version', 'platform'])):
like 'MyDriver', '1.2.3', 'some platform info'. Any of these strings may be
None to accept PyMongo's default.
"""
def __new__(cls, name=None, version=None, platform=None):
def __new__(cls, name, version=None, platform=None):
self = super(DriverInfo, cls).__new__(cls, name, version, platform)
for key, value in self._asdict().items():
if value is not None and not isinstance(value, str):
Expand Down
2 changes: 2 additions & 0 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ def test_metadata(self):
self.assertRaises(ValueError, MongoClient, appname='x' * 129)
# Bad "driver" options.
self.assertRaises(TypeError, DriverInfo, 'Foo', 1, 'a')
self.assertRaises(TypeError, DriverInfo, version="1", platform='a')
self.assertRaises(TypeError, DriverInfo)
self.assertRaises(TypeError, MongoClient, driver=1)
self.assertRaises(TypeError, MongoClient, driver='abc')
self.assertRaises(TypeError, MongoClient, driver=('Foo', '1', 'a'))
Expand Down