SCons.compat package#

Module contents#

SCons compatibility package for old Python versions

This subpackage holds modules that provide backwards-compatible implementations of various things from newer Python versions that we cannot count on because SCons still supported older Pythons.

Other code will not generally reference things in this package through the SCons.compat namespace. The modules included here add things to the builtins namespace or the global module list so that the rest of our code can use the objects and names imported here regardless of Python version. As a result, if this module is used, it should violate the normal convention for imports (standard library imports first, then program-specific imports, each ordered aplhabetically) and needs to be listed first.

The rest of the things here will be in individual compatibility modules that are either: 1) suitably modified copies of the future modules that we want to use; or 2) backwards compatible re-implementations of the specific portions of a future module’s API that we want to use.

GENERAL WARNINGS: Implementations of functions in the SCons.compat modules are NOT guaranteed to be fully compliant with these functions in later versions of Python. We are only concerned with adding functionality that we actually use in SCons, so be wary if you lift this code for other uses. (That said, making these more nearly the same as later, official versions is still a desirable goal, we just don’t need to be obsessive about it.)

We name the compatibility modules with an initial ‘_scons_’ (for example, is our compatibility module for subprocess) so that we can still try to import the real module name and fall back to our compatibility module if we get an ImportError. The import_as() function defined below loads the module as the “real” name (without the ‘_scons’), after which all of the “import {module}” statements in the rest of our code will find our pre-loaded compatibility module.

class SCons.compat.NoSlotsPyPy(name, bases, dct)[source]#

Bases: type

Metaclass for PyPy compatitbility.

PyPy does not work well with __slots__ and __class__ assignment.


Return a type’s method resolution order.

SCons.compat.rename_module(new, old) bool[source]#

Attempt to import the old module and load it under the new name. Used for purely cosmetic name changes in Python 3.x.