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 committed Apr 19, 2024
1 parent 02c4993 commit b6fe390
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flake8_qgis/flake8_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ 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
3 changes: 3 additions & 0 deletions tests/test_flake8_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def test_QGS101_pass():
ret = _results("from qgs.core import QgsMapLayer, QgsVectorLayer")
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")
Expand Down

0 comments on commit b6fe390

Please sign in to comment.