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 mypy for static type checking #1275

Merged
merged 2 commits into from Jan 2, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -17,6 +17,13 @@ repos:
language_version: python3
additional_dependencies:
- flake8-pytest-style
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.790
hooks:
- id: mypy
# Avoid error: Duplicate module named 'setup'
# https://github.com/python/mypy/issues/4008
exclude: ^tests/test_data/
- repo: https://github.com/PyCQA/bandit
rev: 1.7.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion piptools/logging.py
Expand Up @@ -12,7 +12,7 @@
class LogContext:
stream = sys.stderr

def __init__(self, verbosity=0, indent_width=2):
def __init__(self, verbosity: int = 0, indent_width: int = 2):
self.verbosity = verbosity
self.current_indent = 0
self._indent_width = indent_width
Expand Down
Empty file added piptools/py.typed
Empty file.
3 changes: 2 additions & 1 deletion piptools/scripts/compile.py
Expand Up @@ -3,6 +3,7 @@
import sys
import tempfile
import warnings
from typing import Any

from click import Command
from click.utils import safecall
Expand All @@ -25,7 +26,7 @@
DEFAULT_REQUIREMENTS_OUTPUT_FILE = "requirements.txt"


def _get_default_option(option_name):
def _get_default_option(option_name: str) -> Any:
"""
Get default value of the pip's option (including option from pip.conf)
by a given option name.
Expand Down
2 changes: 1 addition & 1 deletion piptools/utils.py
Expand Up @@ -43,7 +43,7 @@ def key_from_req(req):
return key


def comment(text):
def comment(text: str) -> str:
return style(text, fg="green")


Expand Down
14 changes: 14 additions & 0 deletions setup.cfg
Expand Up @@ -69,3 +69,17 @@ pytest-parametrize-values-row-type = tuple

[isort]
profile = black

[mypy]
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
ignore_missing_imports = true
no_implicit_optional = true
strict_equality = true
warn_redundant_casts = true
warn_return_any = true
warn_unused_configs = true
warn_unused_ignores = true