From 4f47303ccbed4dbd6b9cf6e81c710d84a0a01cf4 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sun, 3 Nov 2024 19:32:05 +0200 Subject: [PATCH 1/2] Vendor removed typing._allowed_types --- fastcore/basics.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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()} From e34eb8521483a43a3e71c55683943b43d3187dd9 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:24:25 +0200 Subject: [PATCH 2/2] Vendor removed typing._allowed_types --- nbs/01_basics.ipynb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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()}" ]