Comment

Comment by orf

It’s actually very useful to have context managers outlive their with blocks. They are not only used for files:

One example would be a timing context manager:

   with Timer() as t:
      …
   print(t.runtime)
Another example is mocks, where you want to inspect how many times a mock was called and with what arguments, after the mock context manager has finished.
parent orf 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton