Skip to content
Snippets Groups Projects
Unverified Commit bd918d87 authored by Dan Callahan's avatar Dan Callahan Committed by GitHub
Browse files

Simplify exception handling in is_ascii. (#9985)

We can get away with just catching UnicodeError here.

    ⋮
    +-- ValueError
    |    +-- UnicodeError
    |         +-- UnicodeDecodeError
    |         +-- UnicodeEncodeError
    |         +-- UnicodeTranslateError
    ⋮

https://docs.python.org/3/library/exceptions.html#exception-hierarchy



Signed-off-by: default avatarDan Callahan <danc@element.io>
parent 49808422
No related branches found
No related tags found
No related merge requests found
Simplify a few helper functions.
...@@ -55,9 +55,7 @@ def random_string_with_symbols(length: int) -> str: ...@@ -55,9 +55,7 @@ def random_string_with_symbols(length: int) -> str:
def is_ascii(s: bytes) -> bool: def is_ascii(s: bytes) -> bool:
try: try:
s.decode("ascii").encode("ascii") s.decode("ascii").encode("ascii")
except UnicodeDecodeError: except UnicodeError:
return False
except UnicodeEncodeError:
return False return False
return True return True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment