Skip to content

PYI066: Decide if the rule should apply for sys.version_info checks in boolean expressions #15347

@MichaReiser

Description

@MichaReiser

We considered stabilizing the behavior change that enables PYI066 for nono stub files (see #14059) as part of the 0.9 release (#15340) but ultimately decided against it because we found the following two reports in the ecosystem results:

def _stringify_exception(self, exc: BaseException) -> str:
    try:
        notes = getattr(exc, "__notes__", [])
    except KeyError:
        # Workaround for https://github.com/python/cpython/issues/98778 on
        # Python <= 3.9, and some 3.10 and 3.11 patch versions.
        HTTPError = getattr(sys.modules.get("urllib.error", None), "HTTPError", ())
        if sys.version_info < (3, 12) and isinstance(exc, HTTPError):
            notes = []
        else:
            raise
    tags = WheelTag.compute_best(["x86_64"], py_api="cp39")
    if sys.version_info < (3, 9) or sys.implementation.name != "cpython":
        assert "macosx_10_10_x86_64" in str(tags)
        assert "abi3" not in str(tags)
        assert "cp39" not in str(tags)
    else:
        assert str(tags) == "cp39-abi3-macosx_10_10_x86_64"

While both cases rightfully fall into the scope of the rule, it is fairly opinionated to enforce PYI066. We have to decide if the rule should apply in those cases and, if so, if it should apply both for stub files and regular files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    previewRelated to preview mode featuresruleImplementing 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