Skip to content

Commit

Permalink
Apply monkeytype to twine.commands.check
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrutledge committed Apr 26, 2020
1 parent 7111240 commit 3d58211
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions twine/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
import io
import re
import sys
from io import StringIO
from typing import Any
from typing import List
from typing import Tuple
from typing import Union

import readme_renderer.rst
from pretend import stub

from twine import commands
from twine import package as package_file
Expand All @@ -43,10 +49,10 @@


class _WarningStream:
def __init__(self):
def __init__(self) -> None:
self.output = io.StringIO()

def write(self, text):
def write(self, text: str) -> None:
matched = _REPORT_RE.search(text)

if not matched:
Expand All @@ -61,11 +67,13 @@ def write(self, text):
)
)

def __str__(self):
def __str__(self) -> str:
return self.output.getvalue()


def _check_file(filename, render_warning_stream):
def _check_file(
filename: str, render_warning_stream: Union[str, _WarningStream]
) -> Union[Tuple[List[Any], bool], Tuple[List[str], bool]]:
"""Check given distribution."""
warnings = []
is_ok = True
Expand Down Expand Up @@ -98,7 +106,7 @@ def _check_file(filename, render_warning_stream):


# TODO: Replace with textwrap.indent when Python 2 support is dropped
def _indented(text, prefix):
def _indented(text: str, prefix: str) -> str:
"""Adds 'prefix' to all non-empty lines on 'text'."""

def prefixed_lines():
Expand All @@ -108,7 +116,7 @@ def prefixed_lines():
return "".join(prefixed_lines())


def check(dists, output_stream=sys.stdout):
def check(dists: str, output_stream: StringIO = sys.stdout) -> bool:
uploads = [i for i in commands._find_dists(dists) if not i.endswith(".asc")]
if not uploads: # Return early, if there are no files to check.
output_stream.write("No files to check.\n")
Expand Down Expand Up @@ -144,7 +152,7 @@ def check(dists, output_stream=sys.stdout):
return failure


def main(args):
def main(args: List[str]) -> stub:
parser = argparse.ArgumentParser(prog="twine check")
parser.add_argument(
"dists",
Expand Down

0 comments on commit 3d58211

Please sign in to comment.