Skip to content

Caching a type object does not work #43

@char101

Description

@char101

Hi,

This code works with cachebox 5.1.0 but failed with 5.2.1.

from cachebox import LRUCache, cached

@cached(LRUCache(maxsize=100))
def make_recordclass():
    class A:
        pass
    return A

make_recordclass()

with these errors

EXCEPTION
Traceback (most recent call last):
  File "R:\recordclass\test.py", line 9, in <module>
    line: make_recordclass()
    locals:
      make_recordclass = <local> <function __main__.make_recordclass>
  File "A:\Lang\python\3.14\Lib\site-packages\cachebox\utils.py", line 335, in make_recordclass
    line: _cache[key] = result
  File "A:\Lang\python\3.14\Lib\site-packages\cachebox\_cachebox.py", line 1019, in LRUCache.__setitem__      
    line: self.insert(key, value)
    locals:
      self = <local> cachebox._cachebox.LRUCache[0/100]({}), len = 0
      key = <local> ()
      value = <local> <class __main__.make_recordclass.<locals>.A>
  File "A:\Lang\python\3.14\Lib\site-packages\cachebox\_cachebox.py", line 941, in LRUCache.insert
    line: return self._raw.insert(key, value)
    locals:
      self = <local> cachebox._cachebox.LRUCache[0/100]({}), len = 0
      self._raw = <local> <cachebox._core.LRUCache object at 0x000001B79563F7C0>, len = 0
      key = <local> ()
      value = <local> <class __main__.make_recordclass.<locals>.A>
TypeError: unbound method object.__sizeof__() needs an argument

For context, I was caching a named tuple class using the recordclas library for database result rows based on the column names.

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