-
-
Notifications
You must be signed in to change notification settings - Fork 343
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
Update function open_unix_socket to check the type of filename argument #1399
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,12 +36,13 @@ async def open_unix_socket(filename,): | |
Raises: | ||
OSError: If the socket file could not be connected to. | ||
RuntimeError: If AF_UNIX sockets are not supported. | ||
TypeError: if filename is not str or bytes. | ||
""" | ||
if not has_unix: | ||
raise RuntimeError("Unix sockets are not supported on this platform") | ||
|
||
if filename is None: | ||
raise ValueError("Filename cannot be None") | ||
if not isinstance(filename, (str, trio.Path, bytes)): | ||
raise TypeError("Filename must be str, trio.Path or bytes") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't quite correct... really the criterion is "is the object a valid path". And starting in Python 3.6, the proper way to check that is to use the fspath protocol. So if we want to do this check, then the right way to do it would be something like: filename = os.fspath(filename) This automatically handles all "path-like" objects, including new ones defined in third-party libraries that we've never heard of. And if the user passes in something inappropriate, it gives a good error message: >>> os.fspath(4)
TypeError: expected str, bytes or os.PathLike object, not int Annoyingly, though, we still support Python 3.5 (though not for long, see #1396), so we can't just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the information, I didn't know the function |
||
|
||
# much more simplified logic vs tcp sockets - one socket type and only one | ||
# possible location to connect to | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should mention this in the documentation. It's a general rule that pretty much any Python function can raise
TypeError
if you give it the wrong argument types, and mentioning it explicitly here distracts from more relevant information.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for
TypeError
I removed it