Disallow any Generics on mypy except in black_primer (#2556)

Only black_primer needs the disallowal - means we'll
get better typing everywhere else.
This commit is contained in:
Nipunn Koorapati 2021-10-21 19:38:39 -07:00 committed by GitHub
parent c75abed63e
commit da8a5bb189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 11 deletions

View File

@ -22,8 +22,7 @@ strict_optional=True
warn_no_return=True warn_no_return=True
warn_redundant_casts=True warn_redundant_casts=True
warn_unused_ignores=True warn_unused_ignores=True
# Until we're not supporting 3.6 primer needs this disallow_any_generics=True
disallow_any_generics=False
# The following are off by default. Flip them on if you feel # The following are off by default. Flip them on if you feel
# adventurous. # adventurous.
@ -35,6 +34,11 @@ cache_dir=/dev/null
[mypy-aiohttp.*] [mypy-aiohttp.*]
follow_imports=skip follow_imports=skip
[mypy-black_primer.*]
# Until we're not supporting 3.6 primer needs this
disallow_any_generics=False
[mypy-black] [mypy-black]
# The following is because of `patch_click()`. Remove when # The following is because of `patch_click()`. Remove when
# we drop Python 3.6 support. # we drop Python 3.6 support.

View File

@ -170,7 +170,7 @@ def validate_regex(
ctx: click.Context, ctx: click.Context,
param: click.Parameter, param: click.Parameter,
value: Optional[str], value: Optional[str],
) -> Optional[Pattern]: ) -> Optional[Pattern[str]]:
try: try:
return re_compile_maybe_verbose(value) if value is not None else None return re_compile_maybe_verbose(value) if value is not None else None
except re.error: except re.error:
@ -388,10 +388,10 @@ def main(
quiet: bool, quiet: bool,
verbose: bool, verbose: bool,
required_version: str, required_version: str,
include: Pattern, include: Pattern[str],
exclude: Optional[Pattern], exclude: Optional[Pattern[str]],
extend_exclude: Optional[Pattern], extend_exclude: Optional[Pattern[str]],
force_exclude: Optional[Pattern], force_exclude: Optional[Pattern[str]],
stdin_filename: Optional[str], stdin_filename: Optional[str],
workers: int, workers: int,
src: Tuple[str, ...], src: Tuple[str, ...],

View File

@ -258,7 +258,7 @@ async def git_checkout_or_rebase(
def handle_PermissionError( def handle_PermissionError(
func: Callable, path: Path, exc: Tuple[Any, Any, Any] func: Callable[..., None], path: Path, exc: Tuple[Any, Any, Any]
) -> None: ) -> None:
""" """
Handle PermissionError during shutil.rmtree. Handle PermissionError during shutil.rmtree.

View File

@ -2018,7 +2018,9 @@ def test_get_sources_with_stdin_filename_and_force_exclude(self) -> None:
black_source_lines = _bf.readlines() 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. """Show function calls `from black/__init__.py` as they happen.
Register this with `sys.settrace()` in a test you're debugging. Register this with `sys.settrace()` in a test you're debugging.

View File

@ -11,7 +11,7 @@
from platform import system from platform import system
from subprocess import CalledProcessError from subprocess import CalledProcessError
from tempfile import TemporaryDirectory, gettempdir 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 unittest.mock import Mock, patch
from click.testing import CliRunner from click.testing import CliRunner
@ -44,7 +44,9 @@
@contextmanager @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() old_stdout, sys.stdout = sys.stdout, StringIO()
try: try:
command(*args, **kwargs) command(*args, **kwargs)