Skip to content

Commit

Permalink
Make an exception on _3d import
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LKajan authored and ismogis committed Apr 19, 2024
1 parent a8e159b commit 66c1a3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion flake8_qgis/flake8_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions tests/test_flake8_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 66c1a3a

Please sign in to comment.