fastai/fastcore

Using copy_func on non-function raises NameError

simonkeys opened this issue · 1 comments

copy_func raises NameError because copy is not imported in fastcore.basics:

>> from fastcore.basics import copy_func
>> copy_func(3)

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[185], line 1
----> 1 copy_func(3)

File [~/...], in copy_func(f)
    966 def copy_func(f):
    967     "Copy a non-builtin function (NB `copy.copy` does not work for this)"
--> 968     if not isinstance(f,FunctionType): return copy(f)
    969     fn = FunctionType(f.__code__, f.__globals__, f.__name__, f.__defaults__, f.__closure__)
    970     fn.__kwdefaults__ = f.__kwdefaults__

NameError: name 'copy' is not defined

I actually wouldn't expect copy_func to work on non-functions, though, so maybe just replace return copy(f) with raise ValueError(f'{f} is not a function.')?

Ah thanks will fix -- this is meant to be a general copy that works on everything!