-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ruff_linter: permit asyncio.TimeoutError as an unsafe fix for <3.11
This commit tweaks the TimeoutErrorAlias lint to suggest asyncio.TimeoutError in Python <3.11, but only as an unsafe fix. Namely, in <3.11, asyncio.TimeoutError is not an alias and thus the transformation could change the semantics of the program. In the case where there is a tuple containing both safe and unsafe fixes, I decided to keep it as a single suggested fix and made it overall unsafe. So for example, if Ruff sees this code in Python 3.10: try: pass except (asyncio.TimeoutError, socket.timeout): pass Then it will suggest this as an unsafe fix: try: pass except TimeoutError: pass It could, though, suggest this as a safe fix: try: pass except (asyncio.TimeoutError, TimeoutError): pass since socket.timeout became an alias of TimeoutError in Python 3.10. I opted not to go this route because it wasn't obvious to me that it was worth it. Fixes #8565
- Loading branch information
1 parent
7043846
commit 02bff11
Showing
3 changed files
with
142 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters