Skip to content

False positive --py3k exception-escape in generator expression #3128

Closed
@jboning

Description

@jboning

Steps to reproduce

  1. Create file exception_escape_repro.py with contents:
def foo():
  try:
    return True
  except Exception as ex:
    all(bar for bar in ex.bars)
  1. pylint --py3k exception_escape_repro.py

Current behavior

W:  5,23: Using an exception object that was bound by an except handler (exception-escape)

Expected behavior

No exception escape should be reported.

pylint --version output

$ pylint --version
No config file found, using default configuration
pylint 1.9.5, 
astroid 1.6.6
Python 2.7.16 (default, Jun 19 2019, 07:40:37) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)]

I verified that the issue also occurs with

pylint 2.4.0
astroid 2.3.0
Python 3.7.4 (default, Jul  9 2019, 18:13:23) 
[Clang 10.0.1 (clang-1001.0.46.4)]

I imagine this is due to the combination of function call and generator expression--the function call might store the generator for use later. It would be great if the analysis were clever enough to detect when that's not happening. I suppose this is asking for quite a lot though 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions