Мое определение класса контекстного менеджера:
Код: Выделить всё
import logging
from types import TracebackType
from typing import Optional, Type
class B(A):
def __init__(self):
super().__init__()
self.log = logging.getLogger("B")
def __exit__(
self,
exc_type: Optional[Type[BaseException]],
exc_inst: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> bool:
if exc_inst is not None:
self.log.exception("EXCEPTION!")
return False # let exception propagate
return True
Подробнее здесь: https://stackoverflow.com/questions/791 ... nager-exit
Мобильная версия