[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

2022-02-22 Thread Cooper Lees
Cooper Lees added the comment: FWIW - Will be looking to add to flake8-bugbear here: https://github.com/PyCQA/flake8-bugbear/issues/222 -- ___ Python tracker ___

[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

2022-02-22 Thread Cooper Lees
Cooper Lees added the comment: I would never want to do that ... I understand it's bad. Just questioning things before adding lints so we put things in the right places and more importantly making sure I understand. Thanks for the discussion all. --

[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

2022-02-22 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: No, I say that with suppress(): ... is equivalent to try: ... except (): pass or try: ... except BaseException as err: if not isinstance(err, ()): raise If you want to suppress all

[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

2022-02-22 Thread Zachary Ware
Zachary Ware added the comment: >>> try: ... raise ValueError("I raise...") ... except (): ... pass ... Traceback (most recent call last): File "", line 2, in ValueError: I raise... -- ___ Python tracker

[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

2022-02-22 Thread Cooper Lees
Cooper Lees added the comment: Ok thanks. Looks like the warning in flake8-bugbear is the right place then, unfortunately. And just to be sure: > Note that suppress without arguments corresponds to "except" and isinstance() > with empty tuple. Are you saying that `contextlib.suppress()`

[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

2022-02-22 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I concur with Zachary. Note that suppress without arguments corresponds to "except" and isinstance() with empty tuple. -- nosy: +serhiy.storchaka resolution: -> not a bug stage: -> resolved status: open -> closed

[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

2022-02-22 Thread Zachary Ware
Zachary Ware added the comment: But `suppress` takes varargs; from `suppress`'s perspective, there is no difference between `suppress()` and `l=[];suppress(*l)`. There would be a difference at the AST level, but trying to find it within `suppress` to issue a warning seems unfeasible.

[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

2022-02-21 Thread Cooper Lees
Cooper Lees added the comment: Totally agree with your example use case. There you have a chance for it being useful under certain conditions. In that example there is a passed argument. In my example there is no passed argument. Thus, I believe that this will generally always be developer

[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

2022-02-21 Thread Zachary Ware
Zachary Ware added the comment: I'm -1 on this suggestion; consider the following: ``` exceptions_to_suppress = [] if some_condition: exceptions_to_suppress.append(ValueError) with contextlib.suppress(*exceptions_to_suppress): do_a_thing() ``` This seems a reasonable case to support

[issue46819] Add an Error / Exception / Warning when contextlib.suppress() is entered with no specified exception(s) to suppress

2022-02-21 Thread Cooper Lees
New submission from Cooper Lees : Today if you enter a `contextlib.suppress()` context and specify no exceptions there is no error or warning (I didn't check pywarnings to be fair). Isn't this a useless context then? If not, please explain why and close. If it is, I'd love to discuss