diff --git a/fastcore/basics.py b/fastcore/basics.py index 16d36336..8ccba7b5 100644 --- a/fastcore/basics.py +++ b/fastcore/basics.py @@ -33,6 +33,10 @@ # %% ../nbs/01_basics.ipynb defaults = SimpleNamespace() +_allowed_types = (types.FunctionType, types.BuiltinFunctionType, + types.MethodType, types.ModuleType, + WrapperDescriptorType, MethodWrapperType, MethodDescriptorType) + # %% ../nbs/01_basics.ipynb def ifnone(a, b): "`b` if `a` is None else `a`" @@ -352,7 +356,7 @@ def _eval_type(t, glb, loc): def type_hints(f): "Like `typing.get_type_hints` but returns `{}` if not allowed type" - if not isinstance(f, typing._allowed_types): return {} + if not isinstance(f, _allowed_types): return {} ann,glb,loc = get_annotations_ex(f) return {k:_eval_type(v,glb,loc) for k,v in ann.items()} diff --git a/nbs/01_basics.ipynb b/nbs/01_basics.ipynb index 87be81a5..abc2702e 100644 --- a/nbs/01_basics.ipynb +++ b/nbs/01_basics.ipynb @@ -60,7 +60,11 @@ "outputs": [], "source": [ "#|export\n", - "defaults = SimpleNamespace()" + "defaults = SimpleNamespace()\n", + "\n", + "_allowed_types = (types.FunctionType, types.BuiltinFunctionType,\n", + " types.MethodType, types.ModuleType,\n", + " WrapperDescriptorType, MethodWrapperType, MethodDescriptorType)" ] }, { @@ -1870,7 +1874,7 @@ "\n", "def type_hints(f):\n", " \"Like `typing.get_type_hints` but returns `{}` if not allowed type\"\n", - " if not isinstance(f, typing._allowed_types): return {}\n", + " if not isinstance(f, _allowed_types): return {}\n", " ann,glb,loc = get_annotations_ex(f)\n", " return {k:_eval_type(v,glb,loc) for k,v in ann.items()}" ]