Skip to content

Instantly share code, notes, and snippets.

@wchargin
Created March 30, 2021 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wchargin/ee88bbcf6f096aa95077d5755ce58927 to your computer and use it in GitHub Desktop.
Save wchargin/ee88bbcf6f096aa95077d5755ce58927 to your computer and use it in GitHub Desktop.
calling `cm().__enter__()` on a `@contextlib.contextmanager`
import contextlib
@contextlib.contextmanager
def cm():
print("fst")
yield
print("snd")
cm().__enter__()
$ python3 -V
Python 3.8.7
$ python3 /tmp/test.py
fst
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment