Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use strict mypy settings globally #613

Merged
merged 8 commits into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ show_traceback = True
; https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-type-hints-for-third-party-library
ignore_missing_imports = True

; --strict settings
warn_redundant_casts = True
warn_unused_configs = True
warn_unused_ignores = True

; 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.exceptions,twine.package,twine.repository,twine.utils,twine.wheel,twine.wininst,twine.commands]
; Enabling this will fail on subclasses of untype imports, e.g. tqdm
; Enabling this will fail on subclasses of untyped imports, e.g. tqdm
; disallow_subclassing_any = True
disallow_any_generics = True
disallow_untyped_calls = True
Expand Down
3 changes: 2 additions & 1 deletion twine/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from typing import Any

import requests

from twine import cli
from twine import exceptions


def main():
def main() -> Any:
try:
return cli.dispatch(sys.argv[1:])
except (exceptions.TwineException, requests.HTTPError) as exc:
Expand Down
8 changes: 5 additions & 3 deletions twine/_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
import os
import sys
import warnings
from typing import Optional

import pkginfo


class Installed(pkginfo.Installed):
def read(self):
def read(self) -> Optional[str]:
opj = os.path.join
if self.package is not None:
package = self.package.__package__
if package is None:
package = self.package.__name__
egg_pattern = "%s*.egg-info" % package
dist_pattern = "%s*.dist-info" % package
file = getattr(self.package, "__file__", None)
file: Optional[str] = getattr(self.package, "__file__", None)
if file is not None:
candidates = []

def _add_candidate(where):
def _add_candidate(where: str) -> None:
candidates.extend(glob.glob(where))

for entry in sys.path:
Expand Down Expand Up @@ -56,3 +57,4 @@ def _add_candidate(where):
warnings.warn(
"No PKG-INFO or METADATA found for package: %s" % self.package_name
)
return None
4 changes: 3 additions & 1 deletion twine/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


class CredentialInput:
def __init__(self, username: str = None, password: str = None) -> None:
def __init__(
self, username: Optional[str] = None, password: Optional[str] = None
) -> None:
self.username = username
self.password = password

Expand Down
5 changes: 3 additions & 2 deletions twine/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import textwrap
from typing import IO
from typing import List
from typing import Optional
from typing import Tuple
from typing import cast

Expand Down Expand Up @@ -80,8 +81,8 @@ def _check_file(
package = package_file.PackageFile.from_filename(filename, comment=None)

metadata = package.metadata_dictionary()
description = cast(str, metadata["description"])
description_content_type = cast(str, metadata["description_content_type"])
description = cast(Optional[str], metadata["description"])
description_content_type = cast(Optional[str], metadata["description_content_type"])

if description_content_type is None:
warnings.append(
Expand Down
7 changes: 5 additions & 2 deletions twine/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import collections
import hashlib
import io
import os
import subprocess
from typing import Dict
from typing import NamedTuple
from typing import Optional
from typing import Sequence
from typing import Tuple
Expand Down Expand Up @@ -200,7 +200,10 @@ def run_gpg(cls, gpg_args: Tuple[str, ...]) -> None:
)


Hexdigest = collections.namedtuple("Hexdigest", ["md5", "sha2", "blake2"])
class Hexdigest(NamedTuple):
md5: Optional[str]
sha2: Optional[str]
blake2: Optional[str]


class HashManager:
Expand Down
3 changes: 2 additions & 1 deletion twine/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse
from typing import Any
from typing import Optional
from typing import cast

Expand Down Expand Up @@ -58,7 +59,7 @@ def __init__(
repository_url: Optional[str] = None,
verbose: bool = False,
disable_progress_bar: bool = False,
**ignored_kwargs
**ignored_kwargs: Any,
) -> None:
"""Initialize our settings instance.

Expand Down