Coder Social home page Coder Social logo

Comments (4)

anselor avatar anselor commented on June 2, 2024 1

Thanks for this.

I'll have to set aside some time to play around with it more but I think it's possible if we add a TypeVar declaration like this:

CommandParent = TypeVar('CommandParent', bound=Union[Cmd, CommandSet])

And replace every reference to Cmd or CommandSet in the Callable declarations that would allow subclasses to correctly pass validation.

The declarations would probably need to be changed to something like the following. It would actually simplify it a little bit.

RawCommandFuncOptionalBoolReturn = Callable[[CommandParent, Union[Statement, str]], Optional[bool]]

#: Function signature for a Command Function that uses an argparse.ArgumentParser to process user input
#: and optionally returns a boolean
ArgparseCommandFuncOptionalBoolReturn = Callable[[CommandParent, argparse.Namespace], Optional[bool]]

#: Function signature for a Command Function that uses an argparse.ArgumentParser to process user input
#: and returns a boolean
ArgparseCommandFuncBoolReturn = Callable[[CommandParent, argparse.Namespace], bool]

#: Function signature for an Command Function that uses an argparse.ArgumentParser to process user input
#: and returns nothing
ArgparseCommandFuncNoneReturn = Callable[[CommandParent, argparse.Namespace], None]

#: Aggregate of all accepted function signatures for an argparse Command Function
ArgparseCommandFunc = Union[
    ArgparseCommandFuncOptionalBoolReturn,
    ArgparseCommandFuncBoolReturn,
    ArgparseCommandFuncNoneReturn,
]

from cmd2.

anselor avatar anselor commented on June 2, 2024

@MilanStaffehl
Looks like the changes to type definitions does the trick. I'd appreciate it if you could pull my branch and try it out to verify it also works for you.

There have been a number of fixes recently and I think we should be doing a new release soon.

from cmd2.

MilanStaffehl avatar MilanStaffehl commented on June 2, 2024

I can confirm that with the changes on the branch the problem no longer occurs for me; mypy passes without an error now. Thanks!

Looking forward to the new release, that's another type: ignore I can remove!

from cmd2.

tleonhardt avatar tleonhardt commented on June 2, 2024

I'm closing this since #1276 appears to have addressed it. If I'm wrong, please feel free to re-open.

from cmd2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.