if not conninfo and not kwargs:
return ""
- # If no kwarg is specified don't mung the conninfo but check if it's correct
+ # If no kwarg specified don't mung the conninfo but check if it's correct.
+ # Make sure to return a string, not a subtypep, to avoid making Liskov sad.
if not kwargs:
_parse_conninfo(conninfo)
- return conninfo
+ return str(conninfo)
# Override the conninfo with the parameters
# Drop the None arguments
await AsyncConnection.connect("dbname=nosuchdb")
+async def test_connect_str_subclass(dsn):
+ class MyString(str):
+ pass
+
+ conn = await AsyncConnection.connect(MyString(dsn))
+ assert conn.status == conn.ConnStatus.OK
+
+
async def test_close(aconn):
assert not aconn.closed
await aconn.close()
assert conn.status == conn.ConnStatus.OK
+def test_connect_str_subclass(dsn):
+ class MyString(str):
+ pass
+
+ conn = Connection.connect(MyString(dsn))
+ assert conn.status == conn.ConnStatus.OK
+
+
def test_connect_bad():
with pytest.raises(psycopg3.OperationalError):
Connection.connect("dbname=nosuchdb")