Skip to content

Instantly share code, notes, and snippets.

@PeterJCLaw
Last active January 15, 2021 20:10
Show Gist options
  • Save PeterJCLaw/00b0f5c5a5a6abcf53d2b6d6a8d142c6 to your computer and use it in GitHub Desktop.
Save PeterJCLaw/00b0f5c5a5a6abcf53d2b6d6a8d142c6 to your computer and use it in GitHub Desktop.
Cut-down reproduce for mypy NamedTuple & generic Callable crash
from typing import TypeVar
from .progress_logger import ProgressLogger
# Workaround: uncomment this line.
# Note: doesn't work if the name differs from the TypeVar name in
# progress_logger.py
# T = TypeVar('T')
# Originally (approximately):
# class Foo:
# def bar(self, other: str, *, progress_logger: ProgressLogger) -> None:
# pass
def bar(progress_logger: ProgressLogger) -> None:
pass
from typing import TypeVar, Callable, Iterable, NamedTuple
T = TypeVar('T')
# Originally:
# ProgressLogger = NamedTuple('ProgressLogger', [
# ('info', Callable[[str], None]),
# ('progress', Callable[[Iterable[T]], Iterable[T]]),
# ])
# class ProgressLogger(NamedTuple):
# progress: Callable[[Iterable[T]], Iterable[T]]
class ProgressLogger(NamedTuple):
progress: Callable[[T], T]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment