Skip to content

Make Implementation.UNKNOWN._backend_version() safe #3132

@dangotbanned

Description

@dangotbanned

Noticed another path that can end up here (in #3127 (comment)):

narwhals/narwhals/_utils.py

Lines 632 to 634 in 1471cbb

if implementation is Implementation.UNKNOWN: # pragma: no cover
msg = "Cannot return backend version from UNKNOWN Implementation"
raise AssertionError(msg)

A more reasonable option is to return (0, 0, 0) early - as that can be used in a guard like:

>>> (0, 20, 4) >= (0, 0, 0)
True

In fact, it works for all MIN_VERSIONS:

from narwhals._utils import MIN_VERSIONS

UNKNOWN_VERSION = (0, 0, 0)
>>> all(version >= UNKNOWN_VERSION for version in MIN_VERSIONS.values())
True

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions