@@ -1098,7 +1098,7 @@ def __init__(self, f): self.f = f
10981098 def __get__ (self , _ , f_cls ): return MethodType (self .f , f_cls )
10991099
11001100# %% ../nbs/01_basics.ipynb #3f2733ef
1101- def patch_to (cls , as_prop = False , cls_method = False , set_prop = False , nm = None , glb = None , once : bool = False ):
1101+ def patch_to (cls , as_prop = False , cls_method = False , set_prop = False , nm = None , glb = None ):
11021102 "Decorator: add `f` to `cls`"
11031103 if glb is None : glb = sys ._getframe (1 ).f_globals
11041104 def _inner (f ):
@@ -1113,17 +1113,16 @@ def _inner(f):
11131113 elif set_prop : attr = getattr (c_ , _nm ).setter (nf )
11141114 elif as_prop : attr = property (nf )
11151115 else :
1116- if hasattr (c_ , onm ) and once : break
1117- if hasattr (c_ , _nm ): setattr (c_ , onm , getattr (c_ , _nm ))
1116+ if hasattr (c_ , _nm ) and not hasattr (c_ , onm ): setattr (c_ , onm , getattr (c_ , _nm ))
11181117 attr = nf
11191118 setattr (c_ , _nm , attr )
11201119 return glb .get (_nm , builtins .__dict__ .get (_nm , None ))
11211120 return _inner
11221121
11231122# %% ../nbs/01_basics.ipynb #8faf7b86
1124- def patch (f = None , * , as_prop = False , cls_method = False , set_prop = False , nm = None , once : bool = False ):
1123+ def patch (f = None , * , as_prop = False , cls_method = False , set_prop = False , nm = None ):
11251124 "Decorator: add `f` to the first parameter's class (based on f's type annotations)"
1126- if f is None : return partial (patch , as_prop = as_prop , cls_method = cls_method , set_prop = set_prop , nm = nm , once = once )
1125+ if f is None : return partial (patch , as_prop = as_prop , cls_method = cls_method , set_prop = set_prop , nm = nm )
11271126 ann ,glb ,loc = get_annotations_ex (f )
11281127 if cls_method :
11291128 if 'cls' not in ann : raise TypeError (f"@patch with cls_method=True requires 'cls' to have a type annotation" )
@@ -1132,7 +1131,7 @@ def patch(f=None, *, as_prop=False, cls_method=False, set_prop=False, nm=None, o
11321131 if not ann : raise TypeError (f"@patch requires the first parameter of `{ f .__name__ } ` to have a type annotation" )
11331132 cls = next (iter (ann .values ()))
11341133 cls = union2tuple (eval_type (cls , glb , loc ))
1135- return patch_to (cls , as_prop = as_prop , cls_method = cls_method , set_prop = set_prop , nm = nm , once = once , glb = sys ._getframe (1 ).f_globals )(f )
1134+ return patch_to (cls , as_prop = as_prop , cls_method = cls_method , set_prop = set_prop , nm = nm , glb = sys ._getframe (1 ).f_globals )(f )
11361135
11371136# %% ../nbs/01_basics.ipynb #d1732261
11381137def compile_re (pat ):
0 commit comments