-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Fix error if regex can't find the filename #3285
Fix error if regex can't find the filename #3285
Conversation
Doesn't this just make the error less descriptive? Assuming this is ever hit by users. |
Fixed it. Now it prints an error message more helpful than a non-descriptive It also no longer uses exceptions to control the flow. |
980a746
to
b374bea
Compare
Is this correcting an error you were seeing in the wild? I would not expect AnkiWeb to be be sending a 200 return code if the header is missing. |
No, this is fixing a type error reported by Pyright. Since I use type checkers and linters quite extensively, I'd like them to be happy with the code so that the critical problems can't go unnoticed. If the code is overengineered, I'd like to see this instead (replaced the if-block with an assertion): match = re.match(
"attachment; filename=(.+)", resp.headers["content-disposition"]
)
assert match is not None
fname = match.group(1) |
Happy to see typechecking issues fixed. When we expect something never to be None, I feel an assert better conveys that than an if statement, and it adds less noise to the codebase. |
Done. |
Thanks! |
Ensured that the returned match object is not None.