Skip to content

Index equality raises or reports equality when comparing non-mappings #387

Open

Description

@pabszero

On master ebfa37cd99d7ef716ec452ad8af4b4276a8e2233, Index comparisons with non-mappings can raise or return a false positive.

from tempfile import TemporaryDirectory
from diskcache import Index

with TemporaryDirectory() as directory:
    index = Index(directory)
    try:
        print(index == [])    # True; expected False
        print(index == None)  # TypeError; expected False
    finally:
        index.cache.close()

A populated Index compared with a same-length list raises AttributeError because lists have no get(). Both equality methods should return NotImplemented for non-mappings so Python can try reflected comparisons, as MutableMapping does. Existing order-sensitive Index/OrderedDict comparisons and order-insensitive ordinary mapping comparisons should remain unchanged.

I reproduced 17 regression failures and prepared a focused fix with mapping compatibility controls. This is separate from #378, which handles missing-key sentinel collisions between mappings. Found through code inspection with OpenAI Codex assistance; no production incident is claimed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions