Skip to content

Commit

Permalink
Check for imp availability (due to removal in Python 3.12) and use im…
Browse files Browse the repository at this point in the history
…portlib if necessary. (#1569)
  • Loading branch information
stermart authored Oct 22, 2024
1 parent 462d99a commit e3c68e9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/debugpy/_vendored/pydevd/pydev_ipython/qt_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def has_binding(api):
import importlib

try:
import imp
# importing top level PyQt4/PySide module is ok...
mod = __import__(module_name)
# ...importing submodules is not
Expand All @@ -143,6 +144,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

0 comments on commit e3c68e9

Please sign in to comment.