From e4adb7000dd9cf3688771fd32d0bf52df4f9d58e Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Wed, 13 May 2020 11:08:23 -0600 Subject: Eliminate Py2-compat with_metaclass jig SCons has used a wrapper trick because the way a class declares it uses a metaclass differs between Py2 and Py3. Drop this usage and list the metaclass the Py3 way. Along the way, stop reusing the type class name as a parameter, as it might be confusing (SCons and packaging). Signed-off-by: Mats Wichmann --- SCons/Executor.py | 6 +++--- SCons/Node/__init__.py | 4 ++-- SCons/SConf.py | 4 ++-- SCons/Tool/packaging/__init__.py | 6 +++--- SCons/compat/__init__.py | 42 +++------------------------------------- 5 files changed, 13 insertions(+), 49 deletions(-) diff --git a/SCons/Executor.py b/SCons/Executor.py index fb2224f..e012ab6 100644 --- a/SCons/Executor.py +++ b/SCons/Executor.py @@ -35,7 +35,7 @@ from SCons.Debug import logInstanceCreation import SCons.Errors import SCons.Memoize import SCons.Util -from SCons.compat import with_metaclass, NoSlotsPyPy +from SCons.compat import NoSlotsPyPy class Batch(object): """Remembers exact association between targets @@ -154,7 +154,7 @@ _execute_str_map = {0 : execute_null_str, 1 : execute_actions_str} -class Executor(object, with_metaclass(NoSlotsPyPy)): +class Executor(object, metaclass=NoSlotsPyPy): """A class for controlling instances of executing an action. This largely exists to hold a single association of an action, @@ -587,7 +587,7 @@ def get_NullEnvironment(): nullenv = NullEnvironment() return nullenv -class Null(object, with_metaclass(NoSlotsPyPy)): +class Null(object, metaclass=NoSlotsPyPy): """A null Executor, with a null build Environment, that does nothing when the rest of the methods call it. diff --git a/SCons/Node/__init__.py b/SCons/Node/__init__.py index c3565bf..c1bb822 100644 --- a/SCons/Node/__init__.py +++ b/SCons/Node/__init__.py @@ -62,7 +62,7 @@ from SCons.Util import MD5signature from SCons.Debug import Trace -from SCons.compat import with_metaclass, NoSlotsPyPy +from SCons.compat import NoSlotsPyPy print_duplicate = 0 @@ -511,7 +511,7 @@ class BuildInfoBase(object): setattr(self, key, value) -class Node(object, with_metaclass(NoSlotsPyPy)): +class Node(object, metaclass=NoSlotsPyPy): """The base Node class, for entities that we know how to build, or use to build other Nodes. """ diff --git a/SCons/SConf.py b/SCons/SConf.py index e0e492b..eac4fb0 100644 --- a/SCons/SConf.py +++ b/SCons/SConf.py @@ -64,9 +64,9 @@ SCons.Conftest.LogErrorMessages = 0 build_type = None build_types = ['clean', 'help'] -def SetBuildType(type): +def SetBuildType(buildtype): global build_type - build_type = type + build_type = buildtype # to be set, if we are in dry-run mode dryrun = 0 diff --git a/SCons/Tool/packaging/__init__.py b/SCons/Tool/packaging/__init__.py index b6dd42e..6ac244c 100644 --- a/SCons/Tool/packaging/__init__.py +++ b/SCons/Tool/packaging/__init__.py @@ -121,12 +121,12 @@ def Package(env, target=None, source=None, **kw): PACKAGETYPE=PACKAGETYPE.split(',') # load the needed packagers. - def load_packager(type): + def load_packager(pkgtype): try: # the specific packager is a relative import - return importlib.import_module("." + type, __name__) + return importlib.import_module("." + pkgtype, __name__) except ImportError as e: - raise SConsEnvironmentError("packager %s not available: %s" % (type, str(e))) + raise SConsEnvironmentError("packager %s not available: %s" % (pkgtype, str(e))) packagers = list(map(load_packager, PACKAGETYPE)) diff --git a/SCons/compat/__init__.py b/SCons/compat/__init__.py index 18bef48..abf663d 100644 --- a/SCons/compat/__init__.py +++ b/SCons/compat/__init__.py @@ -96,47 +96,11 @@ except AttributeError: shutil.SameFileError = SameFileError -def with_metaclass(meta, *bases): - """ - Function from jinja2/_compat.py. License: BSD. - - Use it like this:: - - class BaseForm(object): - pass - - class FormType(type): - pass - - class Form(with_metaclass(FormType, BaseForm)): - pass - - This requires a bit of explanation: the basic idea is to make a - dummy metaclass for one level of class instantiation that replaces - itself with the actual metaclass. Because of internal type checks - we also need to make sure that we downgrade the custom metaclass - for one level to something closer to type (that's why __call__ and - __init__ comes back from type etc.). - - This has the advantage over six.with_metaclass of not introducing - dummy classes into the final MRO. - """ - - class metaclass(meta): - __call__ = type.__call__ - __init__ = type.__init__ - - def __new__(cls, name, this_bases, d): - if this_bases is None: - return type.__new__(cls, name, (), d) - return meta(name, bases, d) - - return metaclass('temporary_class', None, {}) - class NoSlotsPyPy(type): - """ - Workaround for PyPy not working well with __slots__ and __class__ assignment. + """ Metaclass for PyPy compatitbility. + + PyPy does not work well with __slots__ and __class__ assignment. """ def __new__(meta, name, bases, dct): -- cgit v0.12