API Reference
is_memo

def is_memo(obj: Any, /) -> bool

Check if a given object is a dbzero memo class or memo instance.

Returns True for classes decorated with @dbzero.memo or instances of such classes. Returns False for primitive types, standard Python collections, and other dbzero types like dbzero.list or dbzero.enum.

Parameters

  • obj Any
    The object or type to inspect.

Returns

True if obj is a class decorated with @dbzero.memo or an instance of such a class, False otherwise.


Examples

Check instances and types

You can use is_memo on both instances and class types to see if they are managed by dbzero.

import dbzero as db0
 
# A regular Python class
class RegularClass:
    pass
 
# A class managed by dbzero
@db0.memo
class MemoClass:
    def __init__(self, value):
        self.value = value
 
# Create an instance of the memoized class
memo_instance = MemoClass(42)
 
# --- Checks ---
 
# Returns True for a @db0.memo class type
assert db0.is_memo(MemoClass) is True
 
# Returns True for an instance of a @db0.memo class
assert db0.is_memo(memo_instance) is True
 
# Returns False for a regular class type
assert db0.is_memo(RegularClass) is False

Check other Python objects

The function will return False for any object that isn't directly a @dbzero.memo class or instance.

# Returns False for primitive types
assert db0.is_memo(123) is False
assert db0.is_memo("hello") is False
 
# Returns False for standard collections
assert db0.is_memo([1, 2, 3]) is False
assert db0.is_memo({"key": "value"}) is False
 
# Returns False for other dbzero types
Colors = db0.enum("Colors", ["RED", "GREEN", "BLUE"])
managed_list = db0.list([1, 2, 3])
 
assert db0.is_memo(Colors.RED) is False
assert db0.is_memo(managed_list) is False