diff --git a/doc/src/extensions.rst b/doc/src/extensions.rst index fa69d628..b661895d 100644 --- a/doc/src/extensions.rst +++ b/doc/src/extensions.rst @@ -497,11 +497,8 @@ Other functions Put together the arguments in *kwargs* into a connection string. If *dsn* is specified too, merge the arguments coming from both the sources. If the - same argument is specified in both the sources, the *kwargs* version - overrides the *dsn* version. - - At least one parameter is required (either *dsn* or any keyword). Note - that the empty string is a valid connection string. + same argument name is specified in both the sources, the *kwargs* value + overrides the *dsn* value. The input arguments are validated: the output should always be a valid connection string (as far as `parse_dsn()` is concerned). If not raise diff --git a/lib/__init__.py b/lib/__init__.py index 698f50d6..829e29eb 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -116,6 +116,9 @@ def connect(dsn=None, connection_factory=None, cursor_factory=None, library: the list of supported parameters depends on the library version. """ + if dsn is None and not kwargs: + raise TypeError('missing dsn and no parameters') + dsn = _ext.make_dsn(dsn, **kwargs) conn = _connect(dsn, connection_factory=connection_factory, async=async) if cursor_factory is not None: diff --git a/lib/extensions.py b/lib/extensions.py index 39cc4de6..21300985 100644 --- a/lib/extensions.py +++ b/lib/extensions.py @@ -158,7 +158,7 @@ class NoneAdapter(object): def make_dsn(dsn=None, **kwargs): """Convert a set of keywords into a connection strings.""" if dsn is None and not kwargs: - raise TypeError('missing dsn and no parameters') + return '' # If no kwarg is specified don't mung the dsn, but verify it if not kwargs: diff --git a/tests/test_connection.py b/tests/test_connection.py index 0158f5cc..ddec8cfc 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -381,8 +381,8 @@ class MakeDsnTestCase(ConnectingTestCase): def assertDsnEqual(self, dsn1, dsn2): self.assertEqual(set(dsn1.split()), set(dsn2.split())) - def test_there_has_to_be_something(self): - self.assertRaises(TypeError, ext.make_dsn) + def test_empty_arguments(self): + self.assertEqual(ext.make_dsn(), '') def test_empty_string(self): dsn = ext.make_dsn('')