Skip to content

with_annotated and with_argparse decorators do not work with staticmethod #1683

Closed

Description

@neoniobium

Problem

with_annotated and with_argparser decorators do not work with the builtin staticmethod decorator.

How to reproduce

class Failed(Cmd):

    @with_annotated
    @staticmethod
    def do_a(...) -> None:
        ...

    @with_argparser
    @staticmethod
    def do_b(...) -> None:
        ...

Expected behavior

Both decorated methods can be declared without a self argument by using the staticmethod decorator for at least one order of decorators.

Actual behavior

Calling booth methods fail with different errors.

Activity

  1. changed the title [-]`with_annotated` and `with_argparse` decorators do not work with `staticmethode`[/-] [+]`with_annotated` and `with_argparse` decorators do not work with `staticmethod`[/+] on Jun 10, 2026
  2. KelvinChung2000 commented on Jun 10, 2026

    @KelvinChung2000
    Contributor

    Using a static method is kind of a strange one, since in cmd2 or cmd in general, it assumes you are working on a class that is your application. Are you trying to do a stateless command? What is the use case of such an implementation?

  3. neoniobium commented on Jun 10, 2026

    @neoniobium
    ContributorAuthor

    Exactly — the idea was to use the static method to indicate that the command should be treated as "stateless."

    I don’t think a feature like that is necessary, so I’m fine with closing this.

  4. tleonhardt commented on Jun 10, 2026

    @tleonhardt
    Member

    I'm going to close this since cmd2 makes the implicit assumption that these decorators will be used with do_* command methods within a cmd2.Cmd or cmd2.CommandSet class.

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