From bb6850969d756ec935d648f4a135ea75e2ab9c39 Mon Sep 17 00:00:00 2001 From: Lauri Kajan Date: Fri, 19 Apr 2024 14:44:29 +0300 Subject: [PATCH] Make an exception on _3d import Usually QGS101 or QGS102 is thrown when importing _ prefixed modules. _3d is currently an exception to this rule, so we should not throw an error when importing it. Importing just 3d would throw and SyntaxError because 3d is not a valid package name because of the leading digit. _3d is the only way to use the 3d module. --- flake8_qgis/flake8_qgis.py | 6 +++++- tests/test_flake8_qgis.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/flake8_qgis/flake8_qgis.py b/flake8_qgis/flake8_qgis.py index 63730bd..5d785e1 100644 --- a/flake8_qgis/flake8_qgis.py +++ b/flake8_qgis/flake8_qgis.py @@ -49,7 +49,11 @@ def _test_qgis_module(module: Optional[str]) -> Optional[str]: if len(modules) < 2: return None - if modules[0] in ("qgs", "qgis") and modules[1].startswith("_"): + if ( + modules[0] in ("qgs", "qgis") + and modules[1].startswith("_") + and modules[1] != "_3d" + ): modules[1] = modules[1][1:] return ".".join(modules) diff --git a/tests/test_flake8_qgis.py b/tests/test_flake8_qgis.py index 48ba618..5b127b9 100644 --- a/tests/test_flake8_qgis.py +++ b/tests/test_flake8_qgis.py @@ -34,6 +34,11 @@ def test_QGS101_pass(): assert ret == set() +def test_QGS101_pass_with_3d_exception(): + ret = _results("from qgis._3d import *") + assert ret == set() + + def test_QGS101(): ret = _results("from qgs._core import QgsMapLayer, QgsVectorLayer") ret = ret.union(_results("from qgis._core import QgsApplication"))