diff --git a/mypy.ini b/mypy.ini index d8eb262f..9167447d 100644 --- a/mypy.ini +++ b/mypy.ini @@ -17,7 +17,7 @@ txt_report = mypy ; TODO: Adopt --strict settings, iterating towards something like: ; https://github.com/pypa/packaging/blob/master/setup.cfg ; Starting with modules that have annotations applied via MonkeyType -[mypy-twine.auth,twine.cli,twine.package,twine.repository,twine.utils] +[mypy-twine.auth,twine.cli,twine.exceptions,twine.package,twine.repository,twine.utils,twine.commands] ; Enabling this will fail on subclasses of untype imports, e.g. tqdm ; disallow_subclassing_any = True disallow_any_generics = True diff --git a/twine/commands/__init__.py b/twine/commands/__init__.py index 68c05e7b..87e83fcc 100644 --- a/twine/commands/__init__.py +++ b/twine/commands/__init__.py @@ -20,7 +20,7 @@ __all__: List[str] = [] -def _group_wheel_files_first(files): +def _group_wheel_files_first(files: List[str]) -> List[str]: if not any(fname for fname in files if fname.endswith(".whl")): # Return early if there's no wheel files return files @@ -30,7 +30,7 @@ def _group_wheel_files_first(files): return files -def _find_dists(dists): +def _find_dists(dists: List[str]) -> List[str]: uploads = [] for filename in dists: if os.path.exists(filename): diff --git a/twine/commands/upload.py b/twine/commands/upload.py index 57bbce12..a37e8bd0 100644 --- a/twine/commands/upload.py +++ b/twine/commands/upload.py @@ -13,6 +13,10 @@ # limitations under the License. import argparse import os.path +from typing import List +from typing import cast + +import requests from twine import commands from twine import exceptions @@ -21,7 +25,9 @@ from twine import utils -def skip_upload(response, skip_existing, package): +def skip_upload( + response: requests.Response, skip_existing: bool, package: package_file.PackageFile +) -> bool: if not skip_existing: return False @@ -44,14 +50,14 @@ def skip_upload(response, skip_existing, package): ) -def upload(upload_settings, dists): +def upload(upload_settings: settings.Settings, dists: List[str]) -> None: dists = commands._find_dists(dists) # Determine if the user has passed in pre-signed distributions signatures = {os.path.basename(d): d for d in dists if d.endswith(".asc")} uploads = [i for i in dists if not i.endswith(".asc")] upload_settings.check_repository_url() - repository_url = upload_settings.repository_config["repository"] + repository_url = cast(str, upload_settings.repository_config["repository"]) print(f"Uploading distributions to {repository_url}") @@ -109,7 +115,7 @@ def upload(upload_settings, dists): repository.close() -def main(args): +def main(args: List[str]) -> None: parser = argparse.ArgumentParser(prog="twine upload") settings.Settings.register_argparse_arguments(parser) parser.add_argument( @@ -122,8 +128,8 @@ def main(args): "file upload.", ) - args = parser.parse_args(args) - upload_settings = settings.Settings.from_argparse(args) + parsed_args = parser.parse_args(args) + upload_settings = settings.Settings.from_argparse(parsed_args) # Call the upload function with the arguments from the command line - return upload(upload_settings, args.dists) + return upload(upload_settings, parsed_args.dists) diff --git a/twine/exceptions.py b/twine/exceptions.py index cb29dee2..d90c70e3 100644 --- a/twine/exceptions.py +++ b/twine/exceptions.py @@ -30,7 +30,7 @@ class RedirectDetected(TwineException): """ @classmethod - def from_args(cls, repository_url, redirect_url): + def from_args(cls, repository_url: str, redirect_url: str) -> "RedirectDetected": msg = "\n".join( [ "{} attempted to redirect to {}.".format(repository_url, redirect_url), @@ -60,7 +60,9 @@ class UploadToDeprecatedPyPIDetected(TwineException): """ @classmethod - def from_args(cls, target_url, default_url, test_url): + def from_args( + cls, target_url: str, default_url: str, test_url: str + ) -> "UploadToDeprecatedPyPIDetected": """Return an UploadToDeprecatedPyPIDetected instance.""" return cls( "You're trying to upload to the legacy PyPI site '{}'. " diff --git a/twine/package.py b/twine/package.py index 9a8ec93e..abfb0c64 100644 --- a/twine/package.py +++ b/twine/package.py @@ -78,7 +78,7 @@ def __init__( self.blake2_256_digest = hexdigest.blake2 @classmethod - def from_filename(cls, filename: str, comment: None) -> "PackageFile": + def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile": # Extract the metadata from the package for ext, dtype in DIST_EXTENSIONS.items(): if filename.endswith(ext): diff --git a/twine/settings.py b/twine/settings.py index 76e5cf09..0cb763de 100644 --- a/twine/settings.py +++ b/twine/settings.py @@ -44,7 +44,7 @@ def __init__( self, *, sign: bool = False, - sign_with: Optional[str] = "gpg", + sign_with: str = "gpg", identity: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, @@ -272,7 +272,7 @@ def from_argparse(cls, args: argparse.Namespace) -> "Settings": return cls(**settings) def _handle_package_signing( - self, sign: bool, sign_with: Optional[str], identity: Optional[str] + self, sign: bool, sign_with: str, identity: Optional[str] ) -> None: if not sign and identity: raise exceptions.InvalidSigningConfiguration(