Skip to content

SIM115 false positive on functions that return file handler objects #13862

@gboeing

Description

@gboeing

ruff 0.7 gives a false positive for SIM115 on something like:

def my_function(filepath, encoding):
    return bz2.open(filepath, mode="rt", encoding=encoding)

which can be resolved like:

def my_function(filepath, encoding):
    with bz2.open(filepath, mode="rt", encoding=encoding) as f:
        return f

But this prevents the calling function from being able to work with f because the context manager has closed it. It seems that SIM115 should not trigger when returning a file handler object from a function?

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedContributions especially welcomeruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions