Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit dbb748c

Browse files
committed
Replace deprecated imp with importlib
Fixes #9642. Signed-off-by: Cristina Muñoz <[email protected]>
1 parent 4dabcf0 commit dbb748c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

synapse/storage/prepare_database.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
import imp
16+
import importlib.util
1717
import logging
1818
import os
1919
import re
@@ -454,8 +454,13 @@ def _upgrade_existing_database(
454454
)
455455

456456
module_name = "synapse.storage.v%d_%s" % (v, root_name)
457-
with open(absolute_path) as python_file:
458-
module = imp.load_source(module_name, absolute_path, python_file) # type: ignore
457+
458+
spec = importlib.util.spec_from_file_location(
459+
module_name, absolute_path
460+
)
461+
module = importlib.util.module_from_spec(spec)
462+
spec.loader.exec_module(module) # type: ignore
463+
459464
logger.info("Running script %s", relative_path)
460465
module.run_create(cur, database_engine) # type: ignore
461466
if not is_empty:

0 commit comments

Comments
 (0)