Comments (4)
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.
@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.
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.
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)
- [1.5.0] `choices_method` does not actually restrict argument choices HOT 2
- [1.5.0] Is it possible to provide a `type` callable access to `self` from within a command set, similar to how `choices_method` works? HOT 3
- 100010953375263
- replay select choices in transcript HOT 3
- overiding perror crashes program for unrecognized errors HOT 2
- Regarding KISS and direction of the project HOT 12
- Enhancing Settables val_type for `bool` HOT 1
- Can I reuse argparser with printing help properly? HOT 2
- CMD2 gives Error 'width must be at least 1' When using Columnize to order a list of items with long names HOT 1
- Sumline
- updating the prompt overwrites incremental search HOT 1
- Can I call Command Scripts from python code? HOT 1
- cmd2 and a-Shell HOT 7
- Edit auto complete in a specific directory HOT 1
- poutput() and ansi styles.
- tttt HOT 1
- Adding a did you mean? or most similar command in case of error HOT 10
- New versions of Statekeeper, ParsedString HOT 3
- Generates an AttributeError when used in a pyinstaller-packaged application HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cmd2.