I have a python function that takes a large amount of parameters :
def func(p1=0, p2=0, p3=0, p4=0, p5=0, ..., pN=0) -> None: pass
I wanted to force the user to set the parameters as keyword arguments.
I thought about one solution that seems off to me:
def func(*_, p1=0, p2=0, p3=0, p4=0, p5=0, ..., pN=0) -> None: pass
I can even raise an error if unwanted ordered arguments were given and even separate ordered arguments from unordered arguments:
def func(p1, p2, p3, *unwanted, p4=0, p5=0, p6=0, ..., pN=0) -> None:
if unwanted: raise TypeError
I haven't seen anyone do this, is there a problem with this?
func(p1, p2, p3, *, p4=0, ..., pN=0)_;*alone is sufficient to mark the "boundary" between ordinary parameters and keyword-only parameters. (*_is the same as*args: it's a parameter named_that gathers any positional arguments not assigned to other parameters. It can also mark the boundary between ordinary and keyword-only parameters.)