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

chore: upgrade to mypy 0.902 #455

Merged
merged 3 commits into from
Jun 20, 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
6 changes: 3 additions & 3 deletions nox/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __new__(
return cast("FunctionDecorator", functools.wraps(func)(obj))


def _copy_func(src: Callable, name: str = None) -> Callable:
def _copy_func(src: Callable, name: Optional[str] = None) -> Callable:
dst = types.FunctionType(
src.__code__,
src.__globals__, # type: ignore
Expand All @@ -41,7 +41,7 @@ def __init__(
name: Optional[str] = None,
venv_backend: Any = None,
venv_params: Any = None,
should_warn: Dict[str, Any] = None,
should_warn: Optional[Dict[str, Any]] = None,
):
self.func = func
self.python = python
Expand All @@ -53,7 +53,7 @@ def __init__(
def __call__(self, *args: Any, **kwargs: Any) -> Any:
return self.func(*args, **kwargs)

def copy(self, name: str = None) -> "Func":
def copy(self, name: Optional[str] = None) -> "Func":
return Func(
_copy_func(self.func, name),
self.python,
Expand Down
3 changes: 2 additions & 1 deletion nox/_option_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import argparse
import collections
import functools
from argparse import ArgumentError, ArgumentParser, Namespace
from argparse import ArgumentError as ArgumentError
from argparse import ArgumentParser, Namespace
from typing import Any, Callable, List, Optional, Tuple, Union

import argcomplete
Expand Down
2 changes: 1 addition & 1 deletion nox/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InvalidVersionSpecifier(Exception):

def get_nox_version() -> str:
"""Return the version of the installed Nox package."""
return metadata.version("nox")
return metadata.version("nox") # type: ignore


def _parse_string_constant(node: ast.AST) -> Optional[str]: # pragma: no cover
Expand Down
9 changes: 7 additions & 2 deletions nox/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
from nox.logger import logger
from nox.popen import popen

if sys.version_info < (3, 8): # pragma: no cover
from typing_extensions import Literal
else: # pragma: no cover
from typing import Literal


class CommandFailed(Exception):
"""Raised when an executed command returns a non-success status code."""

def __init__(self, reason: str = None) -> None:
def __init__(self, reason: Optional[str] = None) -> None:
super(CommandFailed, self).__init__(reason)
self.reason = reason

Expand Down Expand Up @@ -70,7 +75,7 @@ def run(
paths: Optional[List[str]] = None,
success_codes: Optional[Iterable[int]] = None,
log: bool = True,
external: bool = False,
external: Union[Literal["error"], bool] = False,
cjolowicz marked this conversation as resolved.
Show resolved Hide resolved
cjolowicz marked this conversation as resolved.
Show resolved Hide resolved
**popen_kws: Any
) -> Union[str, bool]:
"""Run a command-line program."""
Expand Down
6 changes: 3 additions & 3 deletions nox/popen.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import locale
import subprocess
import sys
from typing import IO, Mapping, Sequence, Tuple, Union
from typing import IO, Mapping, Optional, Sequence, Tuple, Union


def shutdown_process(proc: subprocess.Popen) -> Tuple[bytes, bytes]:
Expand Down Expand Up @@ -54,9 +54,9 @@ def decode_output(output: bytes) -> str:

def popen(
args: Sequence[str],
env: Mapping[str, str] = None,
env: Optional[Mapping[str, str]] = None,
silent: bool = False,
stdout: Union[int, IO] = None,
stdout: Optional[Union[int, IO]] = None,
stderr: Union[int, IO] = subprocess.STDOUT,
) -> Tuple[int, str]:
if silent and stdout is not None:
Expand Down
8 changes: 5 additions & 3 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _run_func(
raise nox.command.CommandFailed()

def run(
self, *args: str, env: Mapping[str, str] = None, **kwargs: Any
self, *args: str, env: Optional[Mapping[str, str]] = None, **kwargs: Any
) -> Optional[Any]:
"""Run a command.

Expand Down Expand Up @@ -269,7 +269,7 @@ def run(
return self._run(*args, env=env, **kwargs)

def run_always(
self, *args: str, env: Mapping[str, str] = None, **kwargs: Any
self, *args: str, env: Optional[Mapping[str, str]] = None, **kwargs: Any
) -> Optional[Any]:
"""Run a command **always**.

Expand Down Expand Up @@ -311,7 +311,9 @@ def run_always(

return self._run(*args, env=env, **kwargs)

def _run(self, *args: str, env: Mapping[str, str] = None, **kwargs: Any) -> Any:
def _run(
self, *args: str, env: Optional[Mapping[str, str]] = None, **kwargs: Any
) -> Any:
"""Like run(), except that it runs even if --install-only is provided."""
# Legacy support - run a function given.
if callable(args[0]):
Expand Down
2 changes: 1 addition & 1 deletion nox/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def load_nox_module(global_config: Namespace) -> Union[types.ModuleType, int]:
os.chdir(os.path.realpath(os.path.dirname(global_config.noxfile)))
return importlib.machinery.SourceFileLoader(
"user_nox_module", global_config.noxfile
).load_module() # type: ignore
).load_module()

except (VersionCheckFailed, InvalidVersionSpecifier) as error:
logger.error(str(error))
Expand Down
4 changes: 3 additions & 1 deletion nox/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class ProcessEnv:
# Special programs that aren't included in the environment.
allowed_globals = () # type: _typing.ClassVar[Tuple[Any, ...]]

def __init__(self, bin_paths: None = None, env: Mapping[str, str] = None) -> None:
def __init__(
self, bin_paths: None = None, env: Optional[Mapping[str, str]] = None
) -> None:
self._bin_paths = bin_paths
self.env = os.environ.copy()
self._reused = False
Expand Down
17 changes: 9 additions & 8 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,16 @@ def blacken(session):

@nox.session(python="3.8")
def lint(session):
session.install("flake8==3.9.2", "black==21.5b2", "isort==5.8.0", "mypy==0.812")
session.run(
"mypy",
"--config-file=",
"--disallow-untyped-defs",
"--warn-unused-ignores",
"--ignore-missing-imports",
"nox",
session.install(
"flake8==3.9.2",
"black==21.6b0",
"isort==5.8.0",
"mypy==0.902",
"types-jinja2",
cjolowicz marked this conversation as resolved.
Show resolved Hide resolved
"packaging",
"importlib_metadata",
)
session.run("mypy")
files = ["nox", "tests", "noxfile.py", "setup.py"]
session.run("black", "--check", *files)
session.run("isort", "--check", *files)
Expand Down
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,26 @@ requires = [
"wheel",
]
build-backend = "setuptools.build_meta"
cjolowicz marked this conversation as resolved.
Show resolved Hide resolved


[tool.mypy]
files = ["nox"]
python_version = "3.6"
warn_unused_configs = true
disallow_any_generics = false
disallow_subclassing_any = false
disallow_untyped_calls = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true
disallow_untyped_decorators = true
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_return_any = false
no_implicit_reexport = true
strict_equality = true

[[tool.mypy.overrides]]
module = [ "argcomplete", "colorlog.*", "py", "tox.*" ]
ignore_missing_imports = true
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"colorlog>=2.6.1,<7.0.0",
"packaging>=20.9",
"py>=1.4.0,<2.0.0",
"typing_extensions>=3.7.4; python_version < '3.8'",
henryiii marked this conversation as resolved.
Show resolved Hide resolved
"virtualenv>=14.0.0",
"importlib_metadata; python_version < '3.8'",
],
Expand Down