From bd691b847c2cb6cbea3450a8749bcc1a67c295e7 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 31 Aug 2021 11:07:46 -0700 Subject: [PATCH] interpreter: use python dunders instead of lock for unpicklability This simplifies things for us, as we don't have to have threading imported for no other reason, and we can remove the `an_unpicklable_object` from the Interpreter and mesonlib, since there was only one user of this. --- mesonbuild/interpreter/interpreter.py | 6 ++++-- mesonbuild/mesonlib/universal.py | 7 ------- unittests/internaltests.py | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index db4f9e9bc..c3e9b4822 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -21,7 +21,7 @@ from .. import optinterpreter from .. import compilers from ..wrap import wrap, WrapMode from .. import mesonlib -from ..mesonlib import HoldableObject, FileMode, MachineChoice, OptionKey, listify, extract_as_list, has_path_sep +from ..mesonlib import MesonBugException, HoldableObject, FileMode, MachineChoice, OptionKey, listify, extract_as_list, has_path_sep from ..programs import ExternalProgram, NonExistingExternalProgram from ..dependencies import Dependency from ..depfile import DepFile @@ -231,7 +231,6 @@ class Interpreter(InterpreterBase, HoldableObject): is_translated: bool = False, ) -> None: super().__init__(_build.environment.get_source_dir(), subdir, subproject) - self.an_unpicklable_object = mesonlib.an_unpicklable_object self.build = _build self.environment = self.build.environment self.coredata = self.environment.get_coredata() @@ -279,6 +278,9 @@ class Interpreter(InterpreterBase, HoldableObject): self.parse_project() self._redetect_machines() + def __getnewargs_ex__(self) -> T.Tuple[T.Tuple[object], T.Dict[str, object]]: + raise MesonBugException('This class is unpicklable') + def _redetect_machines(self): # Re-initialize machine descriptions. We can do a better job now because we # have the compilers needed to gain more knowledge, so wipe out old diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py index 63e754b4e..06b8adf6e 100644 --- a/mesonbuild/mesonlib/universal.py +++ b/mesonbuild/mesonlib/universal.py @@ -44,7 +44,6 @@ _U = T.TypeVar('_U') __all__ = [ 'GIT', - 'an_unpicklable_object', 'python_command', 'project_meson_versions', 'HoldableObject', @@ -265,12 +264,6 @@ def check_direntry_issues(direntry_array: T.Union[T.List[T.Union[str, bytes]], s not pure ASCII. This may cause problems. '''), file=sys.stderr) - -# Put this in objects that should not get dumped to pickle files -# by accident. -import threading -an_unpicklable_object = threading.Lock() - class HoldableObject(metaclass=abc.ABCMeta): ''' Dummy base class for all objects that can be held by an interpreter.baseobjects.ObjectHolder ''' diff --git a/unittests/internaltests.py b/unittests/internaltests.py index 0f2af18b7..8cebeb8ea 100644 --- a/unittests/internaltests.py +++ b/unittests/internaltests.py @@ -1524,6 +1524,6 @@ class InternalTests(unittest.TestCase): build.environment = mock.Mock() build.environment.get_source_dir = mock.Mock(return_value='') with mock.patch('mesonbuild.interpreter.Interpreter._redetect_machines', mock.Mock()), \ - self.assertRaises(Exception): + self.assertRaises(mesonbuild.mesonlib.MesonBugException): i = mesonbuild.interpreter.Interpreter(build, mock=True) pickle.dumps(i)