Skip to content

pyqt5_to_pyqt6.py produces broken syntax for imports #64185

Description

@kannes

What is the bug or the crash?

pyqt5_to_pyqt6.py, at least when run using Oslandia's Docker, produces bad code with the example below.

I did not test this on a non-Docker Qt6 system.

Steps to reproduce the issue

Consider a file with this code inside:

if True:
    ...

from PyQt5.QtCore import QSettings

This is valid Python code and I can execute it with an interpreter just fine.

docker run --rm -v "$(pwd):/home/pyqgisdev/" registry.gitlab.com/oslandia/qgis/pyqgis-4-checker/pyqgis-qt-checker:latest pyqt5_to_pyqt6.py . produces

if True:
    ...

fromqgis.PyQtqgis.PyQt.QtCore import QSettings

where fromqgis.PyQtqgis.PyQt.QtCore is broken, it should be from qgis.PyQt.Qtcore.

Versions

master

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

When I test it in a Qt5 environment I get an assertion error

./scripts/pyqt5_to_pyqt6/pyqt5_to_pyqt6.py /tmp/a                                                                   2 ✘ 
WARNING:root:WARNING: PyQt5 has been found. It may result in wrong behavior.

Traceback (most recent call last):
  File "/home/foo/qgis/./scripts/pyqt5_to_pyqt6/pyqt5_to_pyqt6.py", line 903, in <module>
    raise SystemExit(main())
                     ~~~~^^
  File "/home/foo/qgis/./scripts/pyqt5_to_pyqt6/pyqt5_to_pyqt6.py", line 898, in main
    ret |= fix_file(filename, not args.qgis3_incompatible_changes, dry_run)
           ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/foo/qgis/./scripts/pyqt5_to_pyqt6/pyqt5_to_pyqt6.py", line 719, in fix_file
    assert tokens[i + 2].src == "PyQt5"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

Metadata

Metadata

Assignees

Labels

BugEither a bug report, or a bug fix. Let's hope for the latter!

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions