Skip to content

Commit

Permalink
Add explicit type to cli.dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrutledge committed Apr 27, 2020
1 parent 1fd89a3 commit 26357ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions twine/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from typing import Any
from typing import Union

import requests

from twine import cli
from twine import exceptions


def main() -> Any:
def main() -> Union[cli.CommandResult, str]:
try:
return cli.dispatch(sys.argv[1:])
except (exceptions.TwineException, requests.HTTPError) as exc:
Expand Down
9 changes: 6 additions & 3 deletions twine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
from typing import Any
from typing import Dict
from typing import List
from typing import Optional
from typing import Tuple
from typing import cast

import pkg_resources
import pkginfo
Expand All @@ -27,6 +28,8 @@
import twine
from twine import _installed

CommandResult = Optional[bool]


def _registered_commands(
group: str = "twine.registered_commands",
Expand All @@ -51,7 +54,7 @@ def dep_versions() -> str:
)


def dispatch(argv: List[str]) -> Any:
def dispatch(argv: List[str]) -> CommandResult:
registered_commands = _registered_commands()
parser = argparse.ArgumentParser(prog="twine")
parser.add_argument(
Expand All @@ -70,4 +73,4 @@ def dispatch(argv: List[str]) -> Any:

main = registered_commands[args.command].load()

return main(args.args)
return cast(CommandResult, main(args.args))

0 comments on commit 26357ba

Please sign in to comment.