Но после обновления Mypy до последней версии (1.14.1) я получаю ошибку ниже.
error: Argument 1 to "_redirect_stdout" has incompatible type "StringIO"; expected "TextIOWrapper[_WrappedBuffer]" [arg-type]
Пожалуйста, помогите мне понять
- ошибку
- Что изменилось в mypy, что вызывает ошибку, и
- возможные способы ее устранения.
Спасибо!
@contextlib.contextmanager
def _redirect_stdout(
new_target: io.TextIOWrapper
) -> Generator[io.TextIOWrapper, None, None]:
"""Redirect stdout to the new target.
Args:
new_target: TextIOWrapper. The new target to which stdout is
redirected.
Yields:
TextIOWrapper. The new target.
"""
old_target = sys.stdout
sys.stdout = new_target
try:
yield new_target
finally:
sys.stdout = old_target
target_stdout = io.StringIO()
with _redirect_stdout(target_stdout):
common.print_each_string_after_two_new_lines([
'These', 'are', 'sample', 'strings.'])
self.assertEqual(
target_stdout.getvalue(), 'These\n\nare\n\nsample\n\nstrings.\n\n')
Подробнее здесь: https://stackoverflow.com/questions/793 ... mypy-error
Мобильная версия