GispoCoding / flake8-qgis

Flake8 plugin for QGIS python plugins
MIT License
6 stars 4 forks source link

Imports from qgis._3d are not allowed. #9

Closed jakimowb closed 4 months ago

jakimowb commented 5 months ago

Describe the bug

As it is the only way in python to get classes from the [qgis.3d] Library imported, QGS101 should not complain about imports from qgis._3d. By now QGS101 Use 'from qgis.3d import QgsPoint3DSymbol' instead of 'from qgis._3d import QgsPoint3DSymbol'

To Reproduce

  1. Create a python file that imports the QgsPoint3DSymbol:
from qgis._3d import QgsPoint3DSymbol
  1. run flake8. this produces an error like: QGS101 Use 'from qgis.3d import QgsPoint3DSymbol' instead of 'from qgis._3d import QgsPoint3DSymbol'

Expected behavior

QGS101 should not complain in that specific case, because an import from qgis._3d is the only way to get QgsPoint3DSymbol imported at all.

Environment (please complete the following information):

Additional context Add any other context about the problem here.

LKajan commented 4 months ago

Thanks @jakimowb for raising this!

In general _ prefix is used for the compiled modules and besides of those there is a directory without the _ acting as a "proxy" package that should be used. Now with the _3d module it is different because just 3d would not be a valid package name with having a leading digit which prevents importing that one.

This indeed is currently an issue and the error should probably be ignored in case of _3d as you suggested.