compat

Cross-version compatibility helpers.

New in version 0.12.0.


Provides the following:

PYPY

Type:    bool

True if running on PyPy rather than CPython.

New in version 2.3.0.

PYPY36

Type:    bool

True if running on PyPy 3.6.

New in version 2.6.0.

PYPY37

Type:    bool

True if running on PyPy 3.7.

New in version 2.6.0.

PYPY37_PLUS

Type:    bool

True if running on PyPy 3.7 or newer.

New in version 3.3.0.

PYPY38

Type:    bool

True if running on PyPy 3.8.

New in version 3.2.0.

PYPY38_PLUS

Type:    bool

True if running on PyPy 3.8 or newer.

New in version 3.3.0.

PYPY39

Type:    bool

True if running on PyPy 3.9.

New in version 3.3.0.

PYPY39_PLUS

Type:    bool

True if running on PyPy 3.9 or newer.

New in version 3.3.0.

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.

Parameters

enter_result (Optional[~_T]) – An optional value to return when entering the context. Default None.