question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Forbid `except TypeError or ValueError`

See original GitHub issue

This code should be invalid:

try:
    ...
except TypeError or ValueError:
    ...

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
orsiniumcommented, Sep 14, 2020

can you provide valid example, cause it’s not clear which one should be accepted

Both your examples are valid. The issue is about having an expression inside the except. Another example of a bad code:

def f():
    return ValueError

try:
    raise ValueError
except f():
    print('triggered')

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.

0reactions
sobolevncommented, Oct 5, 2020

Can you please report this to bugbear? And let’s continue without them!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found