Skip to content

Commit c060837

Browse files
authored
Merge pull request #646 from hugovk/fix-allowed-types
Vendor `typing._allowed_types` removed in Python 3.14
2 parents a868b7e + e34eb85 commit c060837

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

fastcore/basics.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
# %% ../nbs/01_basics.ipynb
3434
defaults = SimpleNamespace()
3535

36+
_allowed_types = (types.FunctionType, types.BuiltinFunctionType,
37+
types.MethodType, types.ModuleType,
38+
WrapperDescriptorType, MethodWrapperType, MethodDescriptorType)
39+
3640
# %% ../nbs/01_basics.ipynb
3741
def ifnone(a, b):
3842
"`b` if `a` is None else `a`"
@@ -352,7 +356,7 @@ def _eval_type(t, glb, loc):
352356

353357
def type_hints(f):
354358
"Like `typing.get_type_hints` but returns `{}` if not allowed type"
355-
if not isinstance(f, typing._allowed_types): return {}
359+
if not isinstance(f, _allowed_types): return {}
356360
ann,glb,loc = get_annotations_ex(f)
357361
return {k:_eval_type(v,glb,loc) for k,v in ann.items()}
358362

nbs/01_basics.ipynb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@
6060
"outputs": [],
6161
"source": [
6262
"#|export\n",
63-
"defaults = SimpleNamespace()"
63+
"defaults = SimpleNamespace()\n",
64+
"\n",
65+
"_allowed_types = (types.FunctionType, types.BuiltinFunctionType,\n",
66+
" types.MethodType, types.ModuleType,\n",
67+
" WrapperDescriptorType, MethodWrapperType, MethodDescriptorType)"
6468
]
6569
},
6670
{
@@ -1870,7 +1874,7 @@
18701874
"\n",
18711875
"def type_hints(f):\n",
18721876
" \"Like `typing.get_type_hints` but returns `{}` if not allowed type\"\n",
1873-
" if not isinstance(f, typing._allowed_types): return {}\n",
1877+
" if not isinstance(f, _allowed_types): return {}\n",
18741878
" ann,glb,loc = get_annotations_ex(f)\n",
18751879
" return {k:_eval_type(v,glb,loc) for k,v in ann.items()}"
18761880
]

0 commit comments

Comments
 (0)