Skip to content

Narrow match_arg overload to str-only when several_ok=False#51

Open
Copilot wants to merge 2 commits into
masterfrom
copilot/overload-match-arg-several-ok
Open

Narrow match_arg overload to str-only when several_ok=False#51
Copilot wants to merge 2 commits into
masterfrom
copilot/overload-match-arg-several-ok

Conversation

Copilot AI commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

The first match_arg overload accepted str | Iterable[str] for arg when several_ok=False, but passing an iterable with several_ok=False raises ValueError at runtime. The type signature should reflect this constraint.

  • Narrowed arg from str | Iterable[str] to str in the several_ok: Literal[False] overload
  • Added # type: ignore[call-overload] to tests that intentionally exercise the invalid-type error path
# Before: type checker allows this, but it raises ValueError at runtime
match_arg(["a", "b"], choices, several_ok=False)

# After: type checker correctly rejects it
match_arg(["a", "b"], choices, several_ok=False)  # error: No overloads match

# Valid usages unchanged
match_arg("ban", choices)                          # -> str
match_arg("ban", choices, several_ok=True)         # -> list[str]
match_arg(["a", "b"], choices, several_ok=True)    # -> list[str]
Original prompt

This section details on the original issue you should resolve

<issue_title>match_arg should be overloaded based on several_ok</issue_title>
<issue_description>e.g.

https://github.com/rstudio/pins-python/blob/bdb58e1cba26bae899c73c19871366b417edf113/pins/_adaptors.py#L145-L149</issue_description>

Comments on the Issue (you are @copilot in this section)

@nathanjmcdougall Here's that similar example:
@overload
def create_adaptor(obj: DataFrame) -> DFAdaptor: ...
@overload
def create_adaptor(obj: Any) -> Adaptor: ...
def create_adaptor(obj: Any | DataFrame) -> Adaptor | DFAdaptor:
    if isinstance(obj, AbstractPandasFrame):
        return PandasAdaptor(obj)
    elif isinstance(obj, Adaptor):
        return obj
    else:
        return Adaptor(obj)
```</body></comment_new>
</comments>


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

The first overload previously accepted `str | Iterable[str]` for the `arg`
parameter when `several_ok=False`, but passing an Iterable with
`several_ok=False` raises ValueError at runtime. This change narrows the
type to just `str` so the type system correctly reflects the runtime
behavior, catching invalid calls at type-check time.

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Overload match_arg based on several_ok Narrow match_arg overload to str-only when several_ok=False Mar 19, 2026
Copilot AI requested a review from nathanjmcdougall March 19, 2026 22:41
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review March 19, 2026 22:50
@nathanjmcdougall nathanjmcdougall requested a review from harell March 19, 2026 22:50
@t-t-sonarqube

t-t-sonarqube Bot commented Mar 19, 2026

Copy link
Copy Markdown

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.

match_arg should be overloaded based on several_ok

3 participants