Skip to content

Commit 60feda7

Browse files
committed
get coverage
1 parent 200fec2 commit 60feda7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/idom/core/hooks.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from idom.config import IDOM_DEBUG_MODE
2727
from idom.utils import Ref
2828

29-
from ._f_back import f_module_name
3029
from ._thread_local import ThreadLocal
3130
from .types import ComponentType, Key, VdomDict
3231
from .vdom import vdom
@@ -280,12 +279,15 @@ def use_context(context: Context[_StateType]) -> _StateType:
280279
provider = hook.get_context_provider(context)
281280

282281
if provider is None:
283-
try:
284-
# force type checker to realize this is just a normal function
285-
assert isinstance(context, FunctionType)
286-
return cast(_StateType, context.__kwdefaults__["value"])
287-
except KeyError:
288-
raise TypeError(f"{context} does not implement the Context interface")
282+
# force type checker to realize this is just a normal function
283+
assert isinstance(context, FunctionType), f"{context} is not a Context"
284+
# __kwdefault__ can be None if no kwarg only parameters exist
285+
assert context.__kwdefaults__ is not None, f"{context} has no 'value' kwarg"
286+
# lastly check that 'value' kwarg exists
287+
assert "value" in context.__kwdefaults__, f"{context} has no 'value' kwarg"
288+
# then we can safely access the context's default value
289+
return cast(_StateType, context.__kwdefaults__["value"])
290+
289291
subscribers = provider._subscribers
290292

291293
@use_effect

0 commit comments

Comments
 (0)