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
False positive use 'exception' instead of 'error' when raisign a parser error with argparse
#35
Comments
Hi @Pierre-Sassoulas , thanks for sharing! I got 2 questions for you:
If you don't know about 2, don't worry. I'm mostly brainstorming here. |
Full disclosure I'm biased because I'm maintaining it, but >>> import astroid
>>> a = astroid.extract_node('''
... import argparse
...
... parser = argparse.ArgumentParser()
... parser.add_argument(
... "config_folder", help="Path to the project configuration folder"
... )
... args = parser.parse_args()
... try:
... int(args.config_folder) / 0
... except:
... parser.error(
... f"Your configuration folder can't be divided by zero, use something else !"
... )
... ''')
>>> list(a.handlers[0].body[0].value.func.infer())[0]
<BoundMethod error of argparse.ArgumentParser at 0x140506382647696> |
I disagree that TC400 is an antipattern. The python-docs only say: It does not say: "In an exception handler only this method must be called." I avoid
Then you can make logging if the traceback even conditional if needed. |
@woutervh I welcome you to create a new issue if you're interested in discussing this. Anyway, feel free to go ahead and disable it in your project. |
Fully agree with @woutervh Using For me there's are two drastically different kinds of exceptions. First one is catching Expected exceptions that are more specific and derived from |
In the following code the parser is mistaken for a logger and using parser.exception is suggested :
The text was updated successfully, but these errors were encountered: