Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use importlib instead of imp in qt_loaders.py #1569

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/debugpy/_vendored/pydevd/pydev_ipython/qt_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def has_binding(api):
QT_API_PYQT5: 'PyQt5',
}
module_name = module_name[api]

import imp

try:
import imp
# importing top level PyQt4/PySide module is ok...
mod = __import__(module_name)
# ...importing submodules is not
Expand All @@ -126,6 +126,28 @@ def has_binding(api):
return check_version(mod.__version__, '1.0.3')
else:
return True

except ModuleNotFoundError:
from importlib import machinery

# importing top level PyQt4/PySide module is ok...
mod = __import__(module_name)

# ...importing submodules is not
loader_details = (machinery.ExtensionFileLoader, machinery.EXTENSION_SUFFIXES)
submod_finder = machinery.FileFinder(mod.__path__[0], loader_details)
submod_check = (
submod_finder.find_spec("QtCore") is not None
and submod_finder.find_spec("QtGui") is not None
and submod_finder.find_spec("QtSvg") is not None
)

# we can also safely check PySide version
if api == QT_API_PYSIDE:
return check_version(mod.__version__, '1.0.3') and submod_check
else:
return submod_check

except ImportError:
return False

Expand Down