MAINT: Use of except-pass blocks

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

MAINT: Use of except-pass blocks

Michael Dubravski

Hello everyone,

 

There are multiple instances of except-pass blocks within the codebase that to my knowledge are bad practices (Referencing This StackOverflow Article. For example in numpy/ma/core.py there is an except-pass block that catches all exceptions thrown. Another example of this can be found in numpy/core/function_base.py. I was wondering if it would be a good idea to add some print statements for logging the exceptions caught. Also for cases where except-pass blocks are needed, is there an explanation for not logging exceptions?

 

https://github.com/numpy/numpy/blob/914407d51b878bf7bf34dbd8dd72cc2dbc428673/numpy/ma/core.py#L1034-L1041

 

https://github.com/numpy/numpy/blob/914407d51b878bf7bf34dbd8dd72cc2dbc428673/numpy/core/function_base.py#L461-L472

 

Thanks,

Michael Dubravski


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: MAINT: Use of except-pass blocks

Benjamin Root
In both of those situations, the `pass` aspect makes sense, although they probably should specify a better exception class to catch. The first one, with the copyto() has a comment that explains what is goingon. The second one, dealing with adding to the docstring, is needed because one can run python in the "optimized" mode, which strips out docstrings.

On Tue, Apr 6, 2021 at 2:27 PM Michael Dubravski <[hidden email]> wrote:

Hello everyone,

 

There are multiple instances of except-pass blocks within the codebase that to my knowledge are bad practices (Referencing This StackOverflow Article. For example in numpy/ma/core.py there is an except-pass block that catches all exceptions thrown. Another example of this can be found in numpy/core/function_base.py. I was wondering if it would be a good idea to add some print statements for logging the exceptions caught. Also for cases where except-pass blocks are needed, is there an explanation for not logging exceptions?

 

https://github.com/numpy/numpy/blob/914407d51b878bf7bf34dbd8dd72cc2dbc428673/numpy/ma/core.py#L1034-L1041

 

https://github.com/numpy/numpy/blob/914407d51b878bf7bf34dbd8dd72cc2dbc428673/numpy/core/function_base.py#L461-L472

 

Thanks,

Michael Dubravski

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: MAINT: Use of except-pass blocks

Michael Dubravski

Okay thank you for the input. Do you have any recommendations for the type of exception classes that they could be changed to?

 

From: NumPy-Discussion <numpy-discussion-bounces+mdubravski=[hidden email]> on behalf of Benjamin Root <[hidden email]>
Reply-To: Discussion of Numerical Python <[hidden email]>
Date: Tuesday, April 6, 2021 at 2:58 PM
To: Discussion of Numerical Python <[hidden email]>
Subject: Re: [Numpy-discussion] MAINT: Use of except-pass blocks

 

In both of those situations, the `pass` aspect makes sense, although they probably should specify a better exception class to catch. The first one, with the copyto() has a comment that explains what is goingon. The second one, dealing with adding to the docstring, is needed because one can run python in the "optimized" mode, which strips out docstrings.

 

On Tue, Apr 6, 2021 at 2:27 PM Michael Dubravski <[hidden email]> wrote:

Hello everyone,

 

There are multiple instances of except-pass blocks within the codebase that to my knowledge are bad practices (Referencing This StackOverflow Article. For example in numpy/ma/core.py there is an except-pass block that catches all exceptions thrown. Another example of this can be found in numpy/core/function_base.py. I was wondering if it would be a good idea to add some print statements for logging the exceptions caught. Also for cases where except-pass blocks are needed, is there an explanation for not logging exceptions?

 

https://github.com/numpy/numpy/blob/914407d51b878bf7bf34dbd8dd72cc2dbc428673/numpy/ma/core.py#L1034-L1041

 

https://github.com/numpy/numpy/blob/914407d51b878bf7bf34dbd8dd72cc2dbc428673/numpy/core/function_base.py#L461-L472

 

Thanks,

Michael Dubravski

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________ NumPy-Discussion mailing list [hidden email] https://mail.python.org/mailman/listinfo/numpy-discussion


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: MAINT: Use of except-pass blocks

Eric Wieser
I think the add_docstring one is best left alone, since if it fails once it will probably fail for every docstring in the system, and the logging would be pure noise.

The ma/core one is suspicious - I can't think of any examples where an error would occur, but if you're interested, I'd encourage you to try and come up with a corner-case that enters that `except` block.

Eric

On Tue, Apr 6, 2021, 20:13 Michael Dubravski <[hidden email]> wrote:

Okay thank you for the input. Do you have any recommendations for the type of exception classes that they could be changed to?

 

From: NumPy-Discussion <numpy-discussion-bounces+mdubravski=[hidden email]> on behalf of Benjamin Root <[hidden email]>
Reply-To: Discussion of Numerical Python <[hidden email]>
Date: Tuesday, April 6, 2021 at 2:58 PM
To: Discussion of Numerical Python <[hidden email]>
Subject: Re: [Numpy-discussion] MAINT: Use of except-pass blocks

 

In both of those situations, the `pass` aspect makes sense, although they probably should specify a better exception class to catch. The first one, with the copyto() has a comment that explains what is goingon. The second one, dealing with adding to the docstring, is needed because one can run python in the "optimized" mode, which strips out docstrings.

 

On Tue, Apr 6, 2021 at 2:27 PM Michael Dubravski <[hidden email]> wrote:

Hello everyone,

 

There are multiple instances of except-pass blocks within the codebase that to my knowledge are bad practices (Referencing This StackOverflow Article. For example in numpy/ma/core.py there is an except-pass block that catches all exceptions thrown. Another example of this can be found in numpy/core/function_base.py. I was wondering if it would be a good idea to add some print statements for logging the exceptions caught. Also for cases where except-pass blocks are needed, is there an explanation for not logging exceptions?

 

https://github.com/numpy/numpy/blob/914407d51b878bf7bf34dbd8dd72cc2dbc428673/numpy/ma/core.py#L1034-L1041

 

https://github.com/numpy/numpy/blob/914407d51b878bf7bf34dbd8dd72cc2dbc428673/numpy/core/function_base.py#L461-L472

 

Thanks,

Michael Dubravski

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________ NumPy-Discussion mailing list [hidden email] https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion