summaryrefslogtreecommitdiff
path: root/mako/template.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2021-01-14 08:56:59 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-01-14 13:13:04 -0500
commit92700475248c72f2c3a6e427f754e582a2b575fb (patch)
treee1ccea4a39735de44ec9bca37f3b0ed2575f529e /mako/template.py
parent6215ba10a7737bd3582926b0ade8a510441da48e (diff)
downloadmako-92700475248c72f2c3a6e427f754e582a2b575fb.tar.gz
Avoid warnings under Python 3.10
Fixed Python deprecation issues related to module importing, as well as file access within the Lingua plugin, for deprecated APIs that began to emit warnings under Python 3.10. Pull request courtesy Petr Viktorin. This modernizes the code to avoid `DeprecationWarning` and `ResourceWarning` encountered in the test suite under Python 3.10a4: - [load_module](https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module) is deprecated - Some files weren't being closed This changes the semantics of the `compat.load_module` function: on Python 3.5+, the module is no longer inserted in `sys.modules`. All non-test calls did `del sys.modules[self.module_id]` right after the call, anyway. On older Python, the module is inserted and then deleted. (Some additional `DeprecationWarning` come from Setuptools: https://github.com/pypa/setuptools/pull/2517) Closes: #328 Pull-request: https://github.com/sqlalchemy/mako/pull/328 Pull-request-sha: 87c1d09e5f39de7b19e749568c437928580f7553 Change-Id: I9cb3772f6812ef14297792344caf2f9aa5337adf
Diffstat (limited to 'mako/template.py')
-rw-r--r--mako/template.py3
1 files changed, 0 insertions, 3 deletions
diff --git a/mako/template.py b/mako/template.py
index 3fd0871..5ed2320 100644
--- a/mako/template.py
+++ b/mako/template.py
@@ -12,7 +12,6 @@ import os
import re
import shutil
import stat
-import sys
import tempfile
import types
import weakref
@@ -414,14 +413,12 @@ class Template(object):
self, data, filename, path, self.module_writer
)
module = compat.load_module(self.module_id, path)
- del sys.modules[self.module_id]
if module._magic_number != codegen.MAGIC_NUMBER:
data = util.read_file(filename)
_compile_module_file(
self, data, filename, path, self.module_writer
)
module = compat.load_module(self.module_id, path)
- del sys.modules[self.module_id]
ModuleInfo(module, path, self, filename, None, None, None)
else:
# template filename and no module directory, compile code