Skip to content

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

@CoolCat467

Description

@CoolCat467

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions