From c0af7156b4b8aa57bfe05ac0e0d873598fca8ad6 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 16 Nov 2017 13:14:09 -0600 Subject: [PATCH] Re-Fix: From-string construction: prevent __del__ crash if construction fails (#2 on Gitlab, e02bef63d6f8992f01c32406d0bf2e30ead5db98) --- islpy/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/islpy/__init__.py b/islpy/__init__.py index 1683221..e3009d3 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -183,13 +183,15 @@ def _add_functionality(): if context is None: context = DEFAULT_CONTEXT - # Turns out __del__ is called even if the constructor fails with an - # exception. This is creates a semi-valid state that's just good - # enough to get us past the __del__ method. - self.data = None - - new_me = self.read_from_str(context, s) - self._setup(new_me._release()) + try: + new_me = self.read_from_str(context, s) + except Exception: + # Turns out __del__ is called even if the constructor fails with an + # exception. This is creates a semi-valid state that's just good + # enough to get us past the __del__ method. + self.data = None + else: + self._setup(new_me._release()) def generic_getstate(self): ctx = self.get_ctx() -- GitLab