aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-03-22 14:48:11 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-03-23 13:19:57 +0000
commitb0cf9dc7265d4981a5be03b5a6b6800e99718522 (patch)
tree4f4fa0a67767e1d2d79077fc24dc3315254e3607 /sources
parente4bcfacccaf1c2e5fa0e5a3fdb06266633512e53 (diff)
metaobjectdump.py: Refactor/Fix handling of module imports
The code caused an error when encountering from PySide6 import QtCore since it was expecting from PySide6.QtCore Fix this to handle this case as well. Turn the module list into a set to suppress duplicated modules. Change-Id: I4ec40c28f5a8cc03c7985869597bb2315500a604 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> (cherry picked from commit 1864626470fd615b6012a3b7190c3adec90978e6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'sources')
-rw-r--r--sources/pyside-tools/metaobjectdump.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/sources/pyside-tools/metaobjectdump.py b/sources/pyside-tools/metaobjectdump.py
index c69d9e78f..3588bc497 100644
--- a/sources/pyside-tools/metaobjectdump.py
+++ b/sources/pyside-tools/metaobjectdump.py
@@ -8,7 +8,7 @@ import sys
import tokenize
from argparse import ArgumentParser, RawTextHelpFormatter
from pathlib import Path
-from typing import Dict, List, Optional, Tuple, Union
+from typing import Dict, List, Optional, Set, Tuple, Union
DESCRIPTION = """Parses Python source code to create QObject metatype
@@ -104,7 +104,7 @@ class MetaObjectDumpVisitor(ast.NodeVisitor):
self._properties: List[PropertyEntry] = []
self._signals: List[Signal] = []
self._within_class: bool = False
- self._qt_modules: List[str] = []
+ self._qt_modules: Set[str] = set()
self._qml_import_name = ""
self._qml_import_major_version = 0
self._qml_import_minor_version = 0
@@ -119,7 +119,7 @@ class MetaObjectDumpVisitor(ast.NodeVisitor):
return (self._qml_import_major_version, self._qml_import_minor_version)
def qt_modules(self):
- return self._qt_modules
+ return sorted(self._qt_modules)
@staticmethod
def create_ast(filename: Path) -> ast.Module:
@@ -315,16 +315,20 @@ class MetaObjectDumpVisitor(ast.NodeVisitor):
self._properties.append(prop)
def visit_Import(self, node):
- if node.names:
- self._handle_import(node.names[0].name)
+ for n in node.names: # "import PySide6.QtWidgets"
+ self._handle_import(n.name)
def visit_ImportFrom(self, node):
- self._handle_import(node.module)
+ if "." in node.module: # "from PySide6.QtWidgets import QWidget"
+ self._handle_import(node.module)
+ elif node.module == "PySide6": # "from PySide6 import QtWidgets"
+ for n in node.names:
+ if n.name.startswith("Qt"):
+ self._qt_modules.add(n.name)
def _handle_import(self, mod: str):
- if mod.startswith('PySide'):
- dot = mod.index(".")
- self._qt_modules.append(mod[dot + 1:])
+ if mod.startswith("PySide6."):
+ self._qt_modules.add(mod[8:])
def create_arg_parser(desc: str) -> ArgumentParser: