@@ -667,46 +667,51 @@ def __init__(self, i):
667667# return full_partial
668668
669669
670- def partial_with_offset (func , * partial_args , offset = 1 , ** partial_kwargs ):
671- kwargs_partial = partial (func , ** partial_kwargs )
670+ def partial_with_offset (offset = 1 ):
671+ def bound_partial_with_offset (func , * partial_args , ** partial_kwargs ):
672+ kwargs_partial = partial (func , ** partial_kwargs )
672673
673- @wraps (func )
674- def full_partial (* args , ** kwargs ):
675- full_args = args [:offset ] + partial_args + args [offset :]
676- return kwargs_partial (* full_args , ** kwargs )
674+ @wraps (func )
675+ def full_partial (* args , ** kwargs ):
676+ full_args = args [:offset ] + partial_args + args [offset :]
677+ return kwargs_partial (* full_args , ** kwargs )
677678
678- return full_partial
679+ return full_partial
680+ return bound_partial_with_offset
681+
682+
683+ state_partial = partial_with_offset ()
679684
680685
681686def rename_function (func , name ):
682687 # see functools.wraps
683688 func .__name__ = func .__qualname__ = name
684689
685690
686- scts ["has_equal_name" ] = partial_with_offset (
691+ scts ["has_equal_name" ] = state_partial (
687692 has_equal_part ,
688693 "name" ,
689694 msg = "Make sure to use the correct {{name}}, was expecting {{sol_part[name]}}, instead got {{stu_part[name]}}." ,
690695)
691- scts ["is_default" ] = partial_with_offset (
696+ scts ["is_default" ] = state_partial (
692697 has_equal_part ,
693698 "is_default" ,
694699 msg = "Make sure it {{ 'has' if sol_part.is_default else 'does not have'}} a default argument." ,
695700)
696701
697702# include rest of wrappers
698703for k , v in __PART_WRAPPERS__ .items ():
699- check_fun = partial_with_offset (check_part , k , v )
704+ check_fun = state_partial (check_part , k , v )
700705 rename_function (check_fun , "check_" + k )
701706 scts [check_fun .__name__ ] = check_fun
702707
703708for k , v in __PART_INDEX_WRAPPERS__ .items ():
704- check_fun = partial_with_offset (check_part_index , k , part_msg = v )
709+ check_fun = state_partial (check_part_index , k , part_msg = v )
705710 rename_function (check_fun , "check_" + k )
706711 scts [check_fun .__name__ ] = check_fun
707712
708713for k , v in __NODE_WRAPPERS__ .items ():
709- check_fun = partial_with_offset (check_node , k + "s" , typestr = v ["typestr" ])
714+ check_fun = state_partial (check_node , k + "s" , typestr = v ["typestr" ])
710715 check_fun .__doc__ = Template (v ["docstr" ]).render (
711716 typestr = "typestr: If specified, this overrides the standard way of referring to the construct you're zooming in on." ,
712717 missing_msg = "missing_msg: If specified, this overrides the automatically generated feedback message in case the construct could not be found." ,
0 commit comments