Skip to content

Commit

Permalink
Disallow any Generics on mypy except in black_primer (#2556)
Browse files Browse the repository at this point in the history
Only black_primer needs the disallowal - means we'll
get better typing everywhere else.
  • Loading branch information
nipunn1313 committed Oct 22, 2021
1 parent c75abed commit da8a5bb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
8 changes: 6 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ strict_optional=True
warn_no_return=True
warn_redundant_casts=True
warn_unused_ignores=True
# Until we're not supporting 3.6 primer needs this
disallow_any_generics=False
disallow_any_generics=True

# The following are off by default. Flip them on if you feel
# adventurous.
Expand All @@ -35,6 +34,11 @@ cache_dir=/dev/null

[mypy-aiohttp.*]
follow_imports=skip

[mypy-black_primer.*]
# Until we're not supporting 3.6 primer needs this
disallow_any_generics=False

[mypy-black]
# The following is because of `patch_click()`. Remove when
# we drop Python 3.6 support.
Expand Down
10 changes: 5 additions & 5 deletions src/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def validate_regex(
ctx: click.Context,
param: click.Parameter,
value: Optional[str],
) -> Optional[Pattern]:
) -> Optional[Pattern[str]]:
try:
return re_compile_maybe_verbose(value) if value is not None else None
except re.error:
Expand Down Expand Up @@ -388,10 +388,10 @@ def main(
quiet: bool,
verbose: bool,
required_version: str,
include: Pattern,
exclude: Optional[Pattern],
extend_exclude: Optional[Pattern],
force_exclude: Optional[Pattern],
include: Pattern[str],
exclude: Optional[Pattern[str]],
extend_exclude: Optional[Pattern[str]],
force_exclude: Optional[Pattern[str]],
stdin_filename: Optional[str],
workers: int,
src: Tuple[str, ...],
Expand Down
2 changes: 1 addition & 1 deletion src/black_primer/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ async def git_checkout_or_rebase(


def handle_PermissionError(
func: Callable, path: Path, exc: Tuple[Any, Any, Any]
func: Callable[..., None], path: Path, exc: Tuple[Any, Any, Any]
) -> None:
"""
Handle PermissionError during shutil.rmtree.
Expand Down
4 changes: 3 additions & 1 deletion tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,9 @@ def test_get_sources_with_stdin_filename_and_force_exclude(self) -> None:
black_source_lines = _bf.readlines()


def tracefunc(frame: types.FrameType, event: str, arg: Any) -> Callable:
def tracefunc(
frame: types.FrameType, event: str, arg: Any
) -> Callable[[types.FrameType, str, Any], Any]:
"""Show function calls `from black/__init__.py` as they happen.
Register this with `sys.settrace()` in a test you're debugging.
Expand Down
6 changes: 4 additions & 2 deletions tests/test_primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from platform import system
from subprocess import CalledProcessError
from tempfile import TemporaryDirectory, gettempdir
from typing import Any, Callable, Generator, Iterator, Tuple
from typing import Any, Callable, Iterator, Tuple
from unittest.mock import Mock, patch

from click.testing import CliRunner
Expand Down Expand Up @@ -44,7 +44,9 @@


@contextmanager
def capture_stdout(command: Callable, *args: Any, **kwargs: Any) -> Generator:
def capture_stdout(
command: Callable[..., Any], *args: Any, **kwargs: Any
) -> Iterator[str]:
old_stdout, sys.stdout = sys.stdout, StringIO()
try:
command(*args, **kwargs)
Expand Down

0 comments on commit da8a5bb

Please sign in to comment.