diff options
authorChristian Tismer <>2019-01-04 19:30:03 +0100
committerChristian Tismer <>2019-01-06 07:10:53 +0000
commit60ce66780a82af1314fae9d82ace519815e7a3a1 (patch)
parentff8f597b4581efa48074286cac6f9f1eb1827cd0 (diff)
Fix a rare type hint racing condition
When building type hints during the PySide build, it can happen that the QtMultimedia module already exists, but the QtMultimediaWidgets module is not yet built. Since during the build also directories exist alongside with the not yet existing modules, it can happen that such a directory is picked up by Python 3, which supports namespace modules without . This case was already handled by the mapping modules, but QtMultimediaWidgets was directly imported and not checked. Now the check code has been extracted from the mapping reloader, and there is no more unchecked module left. Task-number: PYSIDE-735 Change-Id: I1a1f53525417651005d0759e417082fe71b02773 Reviewed-by: Cristian Maureira-Fredes <>
2 files changed, 13 insertions, 4 deletions
diff --git a/sources/pyside2/PySide2/support/signature/ b/sources/pyside2/PySide2/support/signature/
index c39821f0..61fa2d41 100644
--- a/sources/pyside2/PySide2/support/signature/
+++ b/sources/pyside2/PySide2/support/signature/
@@ -311,6 +311,8 @@ def init_QtXmlPatterns():
def init_QtMultimedia():
import PySide2.QtMultimediaWidgets
+ # Check if foreign import is valid. See in shiboken2.
+ check_module(PySide2.QtMultimediaWidgets)
"QGraphicsVideoItem": PySide2.QtMultimediaWidgets.QGraphicsVideoItem,
"QVideoWidget": PySide2.QtMultimediaWidgets.QVideoWidget,
diff --git a/sources/shiboken2/shibokenmodule/support/signature/ b/sources/shiboken2/shibokenmodule/support/signature/
index f638bc42..0195f028 100644
--- a/sources/shiboken2/shibokenmodule/support/signature/
+++ b/sources/shiboken2/shibokenmodule/support/signature/
@@ -175,10 +175,7 @@ class Reloader(object):
import_name = prefix + mod_name
if import_name in sys.modules:
# check if this is a real module
- obj = sys.modules[import_name]
- if not getattr(obj, "__file__", None) or os.path.isdir(obj.__file__):
- raise ImportError("Module '{mod_name}' is at most a "
- "namespace!".format(**locals()))
+ check_module(sys.modules[import_name])
# module is real
proc_name = "init_" + mod_name
@@ -193,6 +190,16 @@ class Reloader(object):
# Modules are in place, we can update the type_map.
+def check_module(mod):
+ # During a build, there exist the modules already as directories,
+ # although the '*.so' was not yet created. This causes a problem
+ # in Python 3, because it accepts folders as namespace modules
+ # without enforcing an ''.
+ if not getattr(mod, "__file__", None) or os.path.isdir(mod.__file__):
+ mod_name = mod.__name__
+ raise ImportError("Module '{mod_name}' is at most a namespace!"
+ .format(**locals()))
update_mapping = Reloader().update
type_map = {}