Skip to content

Unhashable objects cannot be used with once_per_instance #57

Description

@aebrahim

Demonstration of the issue:

import once

class Foo:
    def __init__(self, a: int):
        self.a = a

    # defining this without __hash__ make unhashable
    def __eq__(self, other) -> bool:
        if isinstance(other, Foo):
            return self.value == other.value
        return NotImplemented

    @once.once_per_instance
    def b(self) -> int:
        return self.a

a = Foo(a=1)
a.b()

This gives TypeError: unhashable type: 'Foo'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions