Skip to content

Allow method(signature = ) to accept a list of length 1 #555

@dgkf

Description

@dgkf
> library(S7)
>
> fn2 <- new_generic("fn", c("x", "y"))
> method(fn2, list(class_character, class_character)) <- function(x, y, ...) "Hello, World 2!"

So far, so good. When a generic has multiple dispatch args, this works just fine. But even after spending quite a bit of time with S7, I'm hit with this error pretty repeatedly:

> fn <- new_generic("fn", c("x"))
> method(fn, list(class_character)) <- function(x, ...) "Hello, World"
#> Error: Can't convert `signature` to a valid class. Class specification must
#> be an S7 class object, the result of `new_S3_class()`, an S4 class object,
#> or a base class, not a <list>.

In practical use this is just a bit of a nuisance. I seem to constantly be forgetting that the accepted type signature of method()<- changes based on the number of arguments. When I'm in the groove of writing up methods, I always default to writing my signature as a list() because I tend to reach for S7 specifically in the case where multiple dispatch is helpful.

It would be nice if it accepted a list as well for methods that accept a single dispatch arg for the sake of type stability.


I've been on a deep dive using S7 for a package recently and am carving out time to file feedback today. Sorry for the influx of new issues - loving the package overall 🙌

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions