chore: replace `imp` built-in module usage for future Python3.12 usage (#31622)

Signed-off-by: hainenber <dotronghai96@gmail.com>
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
This commit is contained in:
Đỗ Trọng Hải 2025-01-06 23:45:45 +07:00 committed by GitHub
parent 109e6c69ff
commit 5484db34f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -18,7 +18,7 @@
"""Unit tests for Superset"""
from datetime import datetime
import imp
from importlib.util import find_spec
from contextlib import contextmanager
from typing import Any, Union, Optional
from unittest.mock import Mock, patch, MagicMock
@ -256,11 +256,11 @@ class SupersetTestCase(TestCase):
return db.session.query(SqlaTable).filter_by(id=table_id).one()
@staticmethod
def is_module_installed(module_name):
def is_module_installed(module_name: str) -> bool:
try:
imp.find_module(module_name)
return True
except ImportError:
spec = find_spec(module_name)
return spec is not None
except (ModuleNotFoundError, ValueError, TypeError, ImportError):
return False
def get_or_create(self, cls, criteria, **kwargs):