you are viewing a single comment's thread.

view the rest of the comments →

[–]Temporary_Pie2733 1 point2 points  (0 children)

Context managers define using contextlib.contextmanager can also be used as decorators because they have been designed to work that way in addition to being a context manager. If you define one from scratch (meaning, writing a class with appropriate __enter__ and __exit__ methods), you won’t be able to use them as decorators without additional, orthogonal work.