i2mint / i2

Python Mint creation, manipulation, and use
Apache License 2.0
2 stars 1 forks source link

`rm_params` with `allow_removal_of_non_defaulted_params` doesn't exactly work #44

Closed thorwhalen closed 1 year ago

thorwhalen commented 1 year ago

This works:

from slang import fixed_step_chunker
from i2 import FuncFactory, Sig

mk_chunker = FuncFactory(fixed_step_chunker, exclude='it')
chunker = mk_chunker(chk_size=5)
print(f"{Sig(chunker)=}")

wf = range(12)
list(chunker(wf))

But this doesn't:

from slang import fixed_step_chunker
from i2 import FuncFactory, rm_params, Sig

mk_chunker = rm_params(
    FuncFactory(fixed_step_chunker), 
    exclude=['it'], 
    allow_removal_of_non_defaulted_params=True
)
print(f"{Sig(mk_chunker)=}")

wf = range(12)
chunker = mk_chunker(chk_size=5)
print(f"{Sig(chunker)=}")
list(chunker(wf))

But it should.

The reason the above code doesn't work is probably because we should have allow_partial=True in this call to Ingress (in the include_exclude_ingress_factory function)

    return Ingress(inner_sig=sig, outer_sig=sig[include])

But should it be include_exclude_ingress_factory that knows when to have allow_partial=True or not (or should it be always?)? Or should include_exclude_ingress_factory have an allow_partial argument so the user can decide?

image
thorwhalen commented 1 year ago

See what the i2.deco.FuncFactory._process_args_and_kwargs method does. Might be good inspiration for solving this issue.

thorwhalen commented 1 year ago

The thing that might be unintuitive to the novice here is that a FuncFactory instance is a particular kind of callable. Most callables can only be called if all their required arguments (i.e. those that don't have defaults) are given. But in the case of a FuncFactory instance it is not so because it is meant to be a factory where any thing between all and none of the arguments of the wrapped function can be given (having the effect of making a version of the wrapped function where that subset of specified argument have be given default values).

For this reason, made issue: Using a NotSet sentinel to solve make FuncFactory instances' signature more truthful about argument requirements.