How to use isinstance on functools.cache cached classes?

How to use isinstance on functools.cache cached classes?
After working on this answer, I have a cached class to have simple singleton behavior: import functools from dataclasses import dataclass @functools.cache @dataclass(frozen=True) class Person: name: str = "John Doe" age: int = 30 But this doesn't allow to use functions such as isinstance calls as the result function is a _lru_cache_wrapper[Person] instance, not a class: >>> isinstance(p, Person) TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union I don't expect other methods of doing singleton in Python, I already know them, that's not the point. I'm looking for a fix for this specific design using functools.cache on the class symbol itself.

Take Your Experience to the Next Level

New

Download our mobile app for a faster and better experience.

Comments

0
U

Join the discussion

Sign in to leave a comment

0:000:00