Forbid `except TypeError or ValueError`
See original GitHub issueThis code should be invalid:
try:
...
except TypeError or ValueError:
...
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Built-in Exceptions — Python 3.11.1 documentation
In a try statement with an except clause that mentions a particular class, ... the same exception; but beware that there is nothing...
Read more >Why is "except: pass" a bad programming practice?
Unless those exceptions are simple (like ValueError or TypeError ), and the reason why we can pass is obvious, try to avoid just...
Read more >Exception and Error Handling in Python - DataCamp
Value error is raised when the built-in operation or a function receives an argument that has a correct type but invalid value ....
Read more >Exceptions - The Conservative Python 3 Porting Guide
This could result in hard-to-spot bugs: the command except TypeError, ValueError: (note lack of parentheses) will only handle TypeError .
Read more >Exceptions in Python - ZetCode
To prevent this, we must cope with all possible errors that might occur. ... try: # do something except ValueError: # handle ValueError...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Both your examples are valid. The issue is about having an expression inside the
except
. Another example of a bad code:I’ve never seen a dynamically defined
except
like in the example above and I don’t have in mind when it could be useful. Exceptions that should be caught should be explicitly listed.Can you please report this to
bugbear
? And let’s continue without them!