diff --git a/atools/_memoize_decorator.py b/atools/_memoize_decorator.py
index 783caf2..3b0c7ab 100644
--- a/atools/_memoize_decorator.py
+++ b/atools/_memoize_decorator.py
@@ -10,7 +10,7 @@ from sqlite3 import connect, Connection
 from textwrap import dedent
 from time import time
 from threading import Lock as SyncLock
-from typing import Any, Callable, Hashable, Mapping, Optional, Tuple, Type, Union
+from typing import Any, Callable, Dict, Hashable, Mapping, Optional, Tuple, Type, Union
 
 
 Decoratee = Union[Callable, Type]
@@ -57,11 +57,22 @@ class _MemoizeBase:
     keygen: Optional[Keygen]
     size: Optional[int]
 
+    db_eval_types: Optional[Dict[str, Any]] = field(init=False, default=None, hash=False)
     expire_order: OrderedDict = field(init=False, default_factory=OrderedDict, hash=False)
     memos: OrderedDict = field(init=False, default_factory=OrderedDict, hash=False)
 
     def __post_init__(self) -> None:
         if self.db is not None:
+            return_annotation = inspect.signature(self.fn).return_annotation
+            if not hasattr(return_annotation, '__name__'):
+                object.__setattr__(self, 'db_eval_types', dict(self.fn.__globals__))
+            else:
+                object.__setattr__(
+                    self,
+                    'db_eval_types',
+                    {**self.fn.__globals__, return_annotation.__name__: return_annotation}
+                )
+
             self.db.execute(dedent(f'''
                 CREATE TABLE IF NOT EXISTS `{self.table_name}` (
                   k TEXT PRIMARY KEY,
@@ -88,7 +99,7 @@ class _MemoizeBase:
             ).fetchall():
                 memo = self.make_memo(fn=self.fn, t0=t0)
                 memo.memo_return_state.called = True
-                (memo.memo_return_state.value,) = eval(v, __builtins__)
+                (memo.memo_return_state.value,) = eval(v, self.db_eval_types)
                 self.memos[k] = memo
             if self.duration:
                 for k, t0 in self.db.execute(
@@ -159,7 +170,7 @@ class _MemoizeBase:
         else:
             if (self.db is not None) and (self.memos[key] is memo):
                 value = str((memo.memo_return_state.value,))
-                assert (memo.memo_return_state.value,) == eval(value, __builtins__)
+                assert (memo.memo_return_state.value,) == eval(value, self.db_eval_types)
                 self.db.execute(
                     dedent(f'''
                         INSERT OR REPLACE INTO `{self.table_name}`
diff --git a/setup.py b/setup.py
index 45f21de..723457b 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@ from setuptools import find_packages, setup
 
 setup(
     name='atools',
-    version='0.10.2',
+    version='0.10.3',
     packages=find_packages(),
     python_requires='>=3.6',
     url='https://github.com/cevans87/atools',

Use function return type-hint in `eval` when memoize deserializes from db.
For example
```
@memoize(db=True)
def foo() -> pathlib.Path:
    ...
```
This cannot currently be stored and deserialized from the memoize db since we currently only allow deserialization of `__builtins__`. Allowing `__builtins__` _plus_ the return type-hint will greatly expand the usability.
diff --git a/test/test_memoize_decorator.py b/test/test_memoize_decorator.py
index b535cf6..2212b02 100644
--- a/test/test_memoize_decorator.py
+++ b/test/test_memoize_decorator.py
@@ -4,7 +4,7 @@ from asyncio import (
 from atools import memoize
 import atools._memoize_decorator as test_module
 from datetime import timedelta
-from pathlib import Path
+from pathlib import Path, PosixPath
 import pytest
 from sqlite3 import connect, Connection
 from tempfile import NamedTemporaryFile
@@ -572,6 +572,7 @@ async def test_memoize_does_not_stop_object_cleanup() -> None:
     r = ref(f)
     assert r() is not None
     del f
+    # FIXME there's a race condition here. Garbage collector may not have cleaned up f yet
     assert r() is None
 
 
@@ -860,7 +861,7 @@ def test_set_default_db_path_uses_given_path() -> None:
         assert get_table_len(f.name) == 0
 
         @memoize(db=True)
-        def foo():
+        def foo() -> None:
             ...
 
         assert get_table_len(f.name) == 1
@@ -874,9 +875,31 @@ async def test_async_keygen_can_return_non_tuple() -> None:
         return 1
 
     @memoize(keygen=lambda: keygen())
-    async def foo():
+    async def foo() -> None:
         body()
 
     await foo()
     await foo()
     assert body.call_count == 1
+
+
+def test_db_can_return_type_of_return_hint(db: Union[bool, Connection, Path, str]) -> None:
+    class FooPath(PosixPath):
+        pass
+
+    @memoize(db=db)
+    def foo() -> FooPath:
+        return FooPath.cwd()
+
+    assert foo() == FooPath.cwd()
+    assert isinstance(foo(), FooPath)
+
+
+def test_db_can_return_type_of_callers_globals(db: Union[bool, Connection, Path, str]) -> None:
+
+    @memoize(db=db)
+    def foo():
+        return PosixPath.cwd()
+
+    assert foo() == PosixPath.cwd()
+    assert isinstance(foo(), PosixPath)

pip install -e .[u2f]
parse_log_pytest
requirements.txt
nose mock pytest
apt-get update apt-get install -y gcc
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
-e git+https://github.com/cevans87/atools.git@04ef3fc45c951ad09aa07f346e4272d371d078d6#egg=atools
attrs==22.2.0
certifi==2021.5.30
dataclasses==0.8
frozendict==2.4.6
importlib-metadata==4.8.3
iniconfig==1.1.1
mock==5.2.0
nose==1.3.7
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
tomli==1.2.3
typing_extensions==4.1.1
zipp==3.6.0

name: atools
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - dataclasses==0.8
      - frozendict==2.4.6
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - mock==5.2.0
      - nose==1.3.7
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - zipp==3.6.0
prefix: /opt/conda/envs/atools

test/test_memoize_decorator.py::test_db_can_return_type_of_return_hint[bool] test/test_memoize_decorator.py::test_db_can_return_type_of_return_hint[connect] test/test_memoize_decorator.py::test_db_can_return_type_of_return_hint[Path] test/test_memoize_decorator.py::test_db_can_return_type_of_return_hint[str] test/test_memoize_decorator.py::test_db_can_return_type_of_callers_globals[bool] test/test_memoize_decorator.py::test_db_can_return_type_of_callers_globals[connect] test/test_memoize_decorator.py::test_db_can_return_type_of_callers_globals[Path] test/test_memoize_decorator.py::test_db_can_return_type_of_callers_globals[str]
test/test_memoize_decorator.py::test_zero_args test/test_memoize_decorator.py::test_class_function test/test_memoize_decorator.py::test_keyword_same_as_default test/test_memoize_decorator.py::test_sync_size test/test_memoize_decorator.py::test_sync_exception test/test_memoize_decorator.py::test_expire_current_call test/test_memoize_decorator.py::test_expire_old_call test/test_memoize_decorator.py::test_expire_old_item_does_not_expire_new test/test_memoize_decorator.py::test_expire_head_of_line_refresh_does_not_stop_eviction test/test_memoize_decorator.py::test_size_le_zero_raises test/test_memoize_decorator.py::test_expire_le_zero_raises test/test_memoize_decorator.py::test_args_overlaps_kwargs_raises test/test_memoize_decorator.py::test_sync_reset_clears_cache test/test_memoize_decorator.py::test_works_with_property test/test_memoize_decorator.py::test_sync_locks_sync test/test_memoize_decorator.py::test_sync_does_not_async_lock test/test_memoize_decorator.py::test_async_no_event_loop_does_not_raise test/test_memoize_decorator.py::test_memoizes_class test/test_memoize_decorator.py::test_memoizes_class_with_metaclass test/test_memoize_decorator.py::test_reset_all_resets_class_decorators test/test_memoize_decorator.py::test_reset_all_resets_function_decorators test/test_memoize_decorator.py::test_memoize_class_preserves_doc test/test_memoize_decorator.py::test_keygen_overrides_default test/test_memoize_decorator.py::test_db_creates_table_for_each_decorator[bool] test/test_memoize_decorator.py::test_db_creates_table_for_each_decorator[connect] test/test_memoize_decorator.py::test_db_creates_table_for_each_decorator[Path] test/test_memoize_decorator.py::test_db_creates_table_for_each_decorator[str] test/test_memoize_decorator.py::test_db_reloads_values_from_disk[bool] test/test_memoize_decorator.py::test_db_reloads_values_from_disk[connect] test/test_memoize_decorator.py::test_db_reloads_values_from_disk[Path] test/test_memoize_decorator.py::test_db_reloads_values_from_disk[str] test/test_memoize_decorator.py::test_reset_removes_values_on_disk[bool] test/test_memoize_decorator.py::test_reset_removes_values_on_disk[connect] test/test_memoize_decorator.py::test_reset_removes_values_on_disk[Path] test/test_memoize_decorator.py::test_reset_removes_values_on_disk[str] test/test_memoize_decorator.py::test_db_expires_memo[bool] test/test_memoize_decorator.py::test_db_expires_memo[connect] test/test_memoize_decorator.py::test_db_expires_memo[Path] test/test_memoize_decorator.py::test_db_expires_memo[str] test/test_memoize_decorator.py::test_db_memoizes_multiple_values[bool] test/test_memoize_decorator.py::test_db_memoizes_multiple_values[connect] test/test_memoize_decorator.py::test_db_memoizes_multiple_values[Path] test/test_memoize_decorator.py::test_db_memoizes_multiple_values[str] test/test_memoize_decorator.py::test_db_with_size_expires_lru[bool] test/test_memoize_decorator.py::test_db_with_size_expires_lru[connect] test/test_memoize_decorator.py::test_db_with_size_expires_lru[Path] test/test_memoize_decorator.py::test_db_with_size_expires_lru[str] test/test_memoize_decorator.py::test_db_with_duration_expires_stale_values[bool] test/test_memoize_decorator.py::test_db_with_duration_expires_stale_values[connect] test/test_memoize_decorator.py::test_db_with_duration_expires_stale_values[Path] test/test_memoize_decorator.py::test_db_with_duration_expires_stale_values[str] test/test_memoize_decorator.py::test_db_memoizes_frozenset[bool] test/test_memoize_decorator.py::test_db_memoizes_frozenset[connect] test/test_memoize_decorator.py::test_db_memoizes_frozenset[Path] test/test_memoize_decorator.py::test_db_memoizes_frozenset[str] test/test_memoize_decorator.py::test_sync_reset_call_resets_one test/test_memoize_decorator.py::test_reset_call_before_expire_resets_one test/test_memoize_decorator.py::test_reset_call_with_db_resets_call[bool] test/test_memoize_decorator.py::test_reset_call_with_db_resets_call[connect] test/test_memoize_decorator.py::test_reset_call_with_db_resets_call[Path] test/test_memoize_decorator.py::test_reset_call_with_db_resets_call[str] test/test_memoize_decorator.py::test_set_default_db_path_uses_given_path
atools/_memoize_decorator.py setup.py
atools/_memoize_decorator.py setup.py