Skip to content

Model constructors report arguments they do not use - #622

Merged
GidonFrischkorn merged 4 commits into
developfrom
552-constructor-dots
Oct 28, 2026
Merged

GidonFrischkorn merged 4 commits into
developfrom
552-constructor-dots

Conversation

@GidonFrischkorn

Copy link
Copy Markdown
Collaborator

Closes #552 (item 5, the last open one).

Every exported model constructor used to drop an argument it did not know: mpt(trees, foo = 1), sdm("y", foo = 1) and the other 16 returned a model without a word. Each now calls .check_constructor_dots() right after match.call(), which warns, names every unused argument and the constructor, and points to its help page. For a misspelling within two edits of a real argument it adds "Did you mean links?".

What still passes through ..., per constructor:

constructor passed on to the internal deprecated
imm(), IMMfull(), IMMbsc() links setsize
IMMabc() links, nt_distances setsize
mixture3p() links setsize
mixture2p(), sdm(), sdmSimple() links
m3() links, default_priors
mpt() default_priors
cswald(), ddm(), ezdm(), the five sdt_*() nothing

Passed-on names are matched the way R matches them in the internal, by unique prefix: sdm("y", link = ...) reaches links today and is not reported. Unnamed extras are reported too; in sdm() the third one went into links by position.

D1, warning or error: needs your decision. This PR warns, and the message says it becomes an error in bmm 1.6.0. A script with a stray argument has run until now, which fits rule 1 of the lifecycle policy. Erroring now is a one-word change.

D2. Partial matching of a constructor's own formals (sdm("y", vers = "simple")) is left as it is.

A convention test finds the constructors in the namespace (exports with ... that call a .model_*() internal) and fails for any without the check. Once develop is merged into them it fails on #500, #501, #502, #507, #524 and #591-#593; the fix there is one line per constructor. Measured on #524.

Every exported model constructor now warns about a name in `...` that
reaches no consumer, instead of dropping it. The names each constructor
passes on to its .model_*() internal (links, default_priors, IMMabc's
nt_distances) are matched by prefix, as R matches them there, and the
deprecated setsize exactly; unnamed extras are reported too. A close
misspelling gets a "Did you mean" line. The warning says it becomes an
error in bmm 1.6.0.

A convention test finds the constructors in the namespace (exports with
`...` that call a .model_*() internal) and requires the check in each.
…ors (#552)

The constructors' check now matches R's argument matching when an exact name
and a prefix of the same argument appear in one call: `links = ` together
with `l = ` reports `l`, which R drops. A function object as the call head
(`do.call(sdm, ...)`, `Map(sdm, ...)`, `lapply(x, sdm, ...)`) no longer prints
the function's source; the warning says "this model constructor" and gives no
help page.

"Did you mean" needs a name close in proportion to its length, so `xy` no
longer points to `m`, and never offers an argument the call already supplied.
The NEWS entry now also covers an extra argument given by position.

Tests: the setsize exemption is tested for all five constructors that read
it (mixture3p, imm, IMMfull, IMMbsc, IMMabc), with the exact warnings. The
convention test now compares the `known` argument at each call site with the
free formals of the .model_*() internal the constructor calls, and requires
`known` and `deprecated` to be character literals. Added tests for prefix
matching, suggestions and function-object call heads.
…constructor check (#552)

A misspelling is now compared within half its length, at most two edits, so a
transposition in a four or five letter name such as `ilnks` for `links` or
`idst` for `dist` still gets a "Did you mean" hint, while a two-letter name
does not point to a one-letter argument. An argument given twice is reported
once.

The tests can no longer pass on an empty result. Calls are evaluated without
swallowing errors, except in the few that stop after the warning (a required
argument is missing, or the call head is a function object), and each
suggestion test compares the whole message. New tests pin the length rule at
both ends, the exclusion of arguments the call already gave, by exact name or
by prefix, and the count and plural of unnamed arguments.
@GidonFrischkorn
GidonFrischkorn merged commit baaf238 into develop Oct 28, 2026
7 checks passed
@GidonFrischkorn
GidonFrischkorn deleted the 552-constructor-dots branch October 28, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Follow-ups from the MPT review that reach every model

1 participant