Skip to content
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

Ruff v0.7.3 not recognizing instance of SIM115 compared to v0.7.2 #14291

Closed
CoolCat467 opened this issue Nov 12, 2024 · 3 comments
Closed

Ruff v0.7.3 not recognizing instance of SIM115 compared to v0.7.2 #14291

CoolCat467 opened this issue Nov 12, 2024 · 3 comments
Labels
question Asking for support or clarification

Comments

@CoolCat467
Copy link

In Ruff version 0.7.3, SIM115 is not recognized in a case that was recognized in 0.7.2:

file.py

from __future__ import annotations

import traceback
from typing import Any, IO


def open_file(
    filename: str,
    mode: str,
    encoding: str | None = None,
) -> IO[Any] | None:
    """Return file handle. Return None on failure."""
    try:
        # Line below previously correctly triggered `SIM115`
        return open(filename, mode, encoding=encoding)
    except FileNotFoundError:
        print("File Not Found.")
    except (OSError, BaseException) as exc:
        print(exc)
        traceback.print_exception(exc)
    return None

Noted line no longer triggers SIM115, where I argue it might be more correct to do so.

ruff check --isolated --select=SIM115 file.py
~ > ruff --version
ruff 0.7.3
@charliermarsh
Copy link
Member

I believe this was an intentional change.

@zanieb
Copy link
Member

zanieb commented Nov 12, 2024

Yes, per #14066 and #13862

The caller could context manage the returned object. It is incorrect to raise SIM115 here.

@CoolCat467
Copy link
Author

Alright, that makes sense, thanks for clarifying!

@dhruvmanila dhruvmanila added the question Asking for support or clarification label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

4 participants