Last active
August 25, 2022 23:41
-
-
Save jimathyp/11a8c42d987944f5f24d72129dd40e2b to your computer and use it in GitHub Desktop.
Revisions
-
jimathyp revised this gist
Aug 25, 2022 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,21 +4,22 @@ Python context managers context managers provide - the 'with' construct ```python with blah: do-something() ``` a context manager (blah) implements __enter__ and __exit__methods ```python from contextlib import AbstractContextManager ``` https://docs.python.org/3/library/contextlib.html class contextlib.AbstractContextManager An abstract base class for classes that implement object.__enter__() and object.__exit__(). A default implementation for object.__enter__() is provided which returns self while object.__exit__() is an abstract method which by default returns None. See also the definition of Context Manager Types. New in version 3.6. -
jimathyp revised this gist
Aug 25, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Python context managers ======================= context managers provide - the 'with' construct ``` with blah: -
jimathyp renamed this gist
Aug 24, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
jimathyp revised this gist
Aug 24, 2022 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,11 @@ with blah: ``` a context manager (blah) implements __enter__ and __exit__methods ``` from contextlib import AbstractContextManager ``` https://docs.python.org/3/library/contextlib.html -
jimathyp revised this gist
Aug 24, 2022 . 1 changed file with 17 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,4 +11,20 @@ with blah: a context manager (blah) implements __enter__ and __exit__methods https://docs.python.org/3/library/contextlib.html class contextlib.AbstractContextManager An abstract base class for classes that implement object.__enter__() and object.__exit__(). A default implementation for object.__enter__() is provided which returns self while object.__exit__() is an abstract method which by default returns None. See also the definition of Context Manager Types. New in version 3.6. - https://stackoverflow.com/questions/65865543/how-can-i-tell-if-a-function-can-be-used-in-a-context-manager abstract base class Abstract base classes complement duck-typing by providing a way to define interfaces when other techniques like hasattr() would be clumsy or subtly wrong (for example with magic methods). ABCs introduce virtual subclasses, which are classes that don’t inherit from a class but are still recognized by isinstance() and issubclass(); see the abc module documentation. Python comes with many built-in ABCs for data structures (in the collections.abc module), numbers (in the numbers module), streams (in the io module), import finders and loaders (in the importlib.abc module). You can create your own ABCs with the abc module. -
jimathyp created this gist
Aug 24, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ Python context managers ======================= cm - the 'with' construct ``` with blah: do-something() ``` a context manager (blah) implements __enter__ and __exit__methods - https://stackoverflow.com/questions/65865543/how-can-i-tell-if-a-function-can-be-used-in-a-context-manager