-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix n_args_min on many MP_DEFINE_CONST_FUN_OBJ_KW() #5439
Conversation
Thanks! This is extensive, I don't know that I can fairly review it but I'll try. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that actually went faster than I thought. No testing performed, one potential nit raised.
767eed7
to
431e784
Compare
@tannewt Correcting the doc revealed that I2C was using I found no uses of any of these keyword args in the bundle. @jepler and I discussed it briefly, and I made the SPI ones match the I2C ones:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I didn't spot any problems. Hope this is the last round of doc fixes, thanks so much for taking the time to get it right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhalbert Thanks for fixing the inconsistency. I'm ok with the minor breakage.
busio
andbitbangio
.socketpool
andstorage
.#5407 and #5405 discovered that some routines and methods were requiring positional-only args for some required arguments. I think this was mainly a misunderstanding of what
n_args_min
inMP_DEFINE_CONST_FUN_OBJ_KW(obj_name, n_args_min, fun_name)
meant. Thanks to @jepler for pointing this out.n_args_min
here means the minimum of positional-only arguments required. It does not need to be used to specify the minimum number of arguments.MP_ARG_REQUIRED
takes care of requiring any particular argument, and gives a better error if the argument missing (e.g., instead of "function missing 1 required positional arguments", we get an error like "'buffer' argument required").In general,
n_args_min
can always be 0, when the function is a plain function, or 1, when it's a method. The one argument isself
in the latter case.I did a little other cleanup, fixing some incorrect
Optional[int]
args and usingbuffer
consistently instead ofbuf
inbusio
andbitbangio
,and regularzing some arg parsing insocketpool
andstorage
.I tested a number of these changes in the REPL to make sure they were still requiring the right args, and could be used with and without keywords, including the trickier changes in
socketpool
andstorage
.