compat
Cross-version compatibility helpers.
New in version 0.12.0.
Provides the following:
-
importlib_resources
importlib_resources on Python 3.6;
importlib.resources
on Python 3.7 and later.
-
importlib_metadata
importlib_metadata on Python 3.8 and earlier;
importlib.metadata
on Python 3.9 and later.New in version 1.1.0.
Changed in version 2.5.0: importlib_metadata is now used on Python 3.8 in place of the stdlib version.
-
class
nullcontext
(enter_result=None)[source] Bases:
ContextManager
[Optional
[~_T
]]Context manager that does no additional processing.
Used as a stand-in for a normal context manager, when a particular block of code is only sometimes used with a normal context manager:
cm = optional_cm if condition else nullcontext() with cm: # Perform operation, using optional_cm if condition is True
New in version 2.1.0.
In Python 3.7 and above the version from the standard library is used instead of this one, but the implementations are identical.