Skip to content

Commit 9e75d1e

Browse files
benhoytaaugustin
authored andcommitted
Fix docstring of parse_uri to reflect the exception type raised
It doesn't raise a ValueError, but an InvalidURI error (see below). If we want the exception type to be a ValueError as well, you could make InvalidURI inherit from ValueError as well as WebSocketException. But just changing the doc seems like the right fix here. >>> from websockets.uri import parse_uri >>> parse_uri('foo://example.com') Traceback (most recent call last): File "/home/ben/w/websockets/src/websockets/uri.py", line 58, in parse_uri assert parsed.scheme in ["ws", "wss"] AssertionError The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/ben/w/websockets/src/websockets/uri.py", line 63, in parse_uri raise exceptions.InvalidURI(uri) from exc websockets.exceptions.InvalidURI: foo://example.com isn't a valid URI >>> import sys >>> exc = sys.last_value >>> isinstance(exc, ValueError) False
1 parent 4b10c2c commit 9e75d1e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/websockets/uri.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def parse_uri(uri: str) -> WebSocketURI:
4949
"""
5050
Parse and validate a WebSocket URI.
5151
52-
:raises ValueError: if ``uri`` isn't a valid WebSocket URI.
52+
:raises ~websockets.exceptions.InvalidURI: if ``uri`` isn't a valid
53+
WebSocket URI.
5354
5455
"""
5556
parsed = urllib.parse.urlparse(uri)

0 commit comments

Comments
 (0)