From 0ab68b2d4f6ad0efce45e56df8e94778fe7f758c Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sun, 16 May 2021 10:36:42 +0200 Subject: Revert "Fix bug in Magic when destructor called too early" This reverts commit 16972c2c6fda3573860f5f8b0f2c03b757e71d3c. --- magic/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/magic/__init__.py b/magic/__init__.py index f10a38a..17456c1 100644 --- a/magic/__init__.py +++ b/magic/__init__.py @@ -53,8 +53,6 @@ class Magic: raw - Do not try to decode "non-printable" chars. extension - Print a slash-separated list of valid extensions for the file type found. """ - - self.cookie = None self.flags = MAGIC_NONE if mime: self.flags |= MAGIC_MIME_TYPE -- cgit v1.2.1 From 12d0ea062d92a15baee69c4be0e4ae00fcdee416 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sun, 16 May 2021 10:37:25 +0200 Subject: Check for cookie attribute before trying to delete it __del__ is called regardless of whether __init__ passed, so the cookie attribute may not exits. This can be seen with: python3 -c "import magic; magic.Magic(foo=None)" Also discussed in https://github.com/ahupp/python-magic/pull/222#issuecomment-675354824 --- magic/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/magic/__init__.py b/magic/__init__.py index 17456c1..363e88f 100644 --- a/magic/__init__.py +++ b/magic/__init__.py @@ -150,7 +150,7 @@ class Magic: # incorrect fix for a threading problem, however I'm leaving # it in because it's harmless and I'm slightly afraid to # remove it. - if self.cookie and magic_close: + if hasattr(self, 'cookie') and self.cookie and magic_close: magic_close(self.cookie) self.cookie = None -- cgit v1.2.1