diff --git a/trio/_highlevel_open_unix_stream.py b/trio/_highlevel_open_unix_stream.py index 5992c4f73e..59141ebc38 100644 --- a/trio/_highlevel_open_unix_stream.py +++ b/trio/_highlevel_open_unix_stream.py @@ -40,13 +40,10 @@ async def open_unix_socket(filename,): if not has_unix: raise RuntimeError("Unix sockets are not supported on this platform") - if filename is None: - raise ValueError("Filename cannot be None") - # much more simplified logic vs tcp sockets - one socket type and only one # possible location to connect to sock = socket(AF_UNIX, SOCK_STREAM) with close_on_error(sock): - await sock.connect(filename) + await sock.connect(trio._util.fspath(filename)) return trio.SocketStream(sock) diff --git a/trio/tests/test_highlevel_open_unix_stream.py b/trio/tests/test_highlevel_open_unix_stream.py index c66028b14f..872a43dd6d 100644 --- a/trio/tests/test_highlevel_open_unix_stream.py +++ b/trio/tests/test_highlevel_open_unix_stream.py @@ -30,6 +30,12 @@ def close(self): assert c.closed +@pytest.mark.parametrize('filename', [4, 4.5]) +async def test_open_with_bad_filename_type(filename): + with pytest.raises(TypeError): + await open_unix_socket(filename) + + async def test_open_bad_socket(): # mktemp is marked as insecure, but that's okay, we don't want the file to # exist