Last active
January 15, 2021 20:10
-
-
Save PeterJCLaw/00b0f5c5a5a6abcf53d2b6d6a8d142c6 to your computer and use it in GitHub Desktop.
Cut-down reproduce for mypy NamedTuple & generic Callable crash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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