Skip to content

Restrict allowed "verbose" values, or make the verbose kwarg a keyword-only argument? #8258

Closed

Description

@hoechenberger

Call me stupid but I just spent 5 minutes trying to "debug" why this wasn't doing as I expected:

epochs.apply_baseline(None, 0)

Obviously, the baseline period should be specified as a tuple… What happened here is that instead of throwing an error message, I ended up with Epochs without baseline correction. Signature of apply_baseline is:

    @verbose
    def apply_baseline(self, baseline=(None, 0), verbose=None):

So verbose was simply set to 0.

While you could always argue that of course you should check your results and that you cannot make a software fool-proof, I was still wondering if we couldn't easily prevent some of those "user bugs" from happening. In this particular case, either being more restrictive on the allowed values of verbose, or declaring verbose to be a keyword-only argument would have successfully mitigated my inaptness :)

    def apply_baseline(self, baseline=(None, 0), *, verbose=None):

Thoughts?

Activity

  1. cbrnr commented on Sep 15, 2020

    @cbrnr
    Contributor

    I like both suggestions: make verbose a kw-only argument and restrict its values.

  2. hoechenberger commented on Sep 15, 2020

    @hoechenberger
    MemberAuthor

    There's a third (complementary) solution: at one point, we should start discussing adding type annotations.

  3. cbrnr commented on Sep 15, 2020

    @cbrnr
    Contributor

    Let's try to move this point as far as possible into the future...

  4. larsoner commented on Sep 15, 2020

    @larsoner
    Member

    I'm fine with adding the * to functions where verbose is close to the other arguments. We can even just start with apply_baseline for 0.21 as I agree it's a likely candidate for this problem.

    I'm also fine with making the verbose decorator more picky, but let's do that early in 0.22

  5. hoechenberger commented on Sep 15, 2020

    @hoechenberger
    MemberAuthor

    We can even just start with apply_baseline for 0.21 as I agree it's a likely candidate for this problem.

    I can do this later tonight I believe.

  6. agramfort commented on Sep 15, 2020

    @agramfort
    SponsorMember
  7. hoechenberger commented on Sep 15, 2020

    @hoechenberger
    MemberAuthor

    np.zeros(2, 3) :)

    I literally had to run this code to figure out what's wrong with it. Ouch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions