Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QgsMessageLevel::None cannot be used in Python #42996

Closed
gacarrillor opened this issue Apr 27, 2021 · 0 comments · Fixed by #43443
Closed

QgsMessageLevel::None cannot be used in Python #42996

gacarrillor opened this issue Apr 27, 2021 · 0 comments · Fixed by #43443
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! PyQGIS Related to the PyQGIS API

Comments

@gacarrillor
Copy link
Member

The docs mention a QgsMessageLevel::None (C++) or QgsMessageLevel.None (Python) value that cannot be accessed in Python.

If Python devs attempt to use the Qgis.None, they'll get this error:

>>> Qgis.None
Traceback (most recent call last):
  File "/usr/lib/python3.8/code.py", line 63, in runsource
    code = self.compile(source, filename, symbol)
  File "/usr/lib/python3.8/codeop.py", line 176, in __call__
    return _maybe_compile(self.compiler, source, filename, symbol)
  File "/usr/lib/python3.8/codeop.py", line 104, in _maybe_compile
    raise err1
  File "/usr/lib/python3.8/codeop.py", line 91, in _maybe_compile
    code1 = compiler(source + "\n", filename, symbol)
  File "/usr/lib/python3.8/codeop.py", line 141, in __call__
    codeob = compile(source, filename, symbol, self.flags, 1)
  File "<input>", line 1
    Qgis.None
         ^
SyntaxError: invalid syntax

The corresponding SIP file also mentions the value None.

To enable this reserved name in Python, could we think about options like Qgis._None / Qgis.none or something like that?

@gacarrillor gacarrillor added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Apr 27, 2021
@gioman gioman added the PyQGIS Related to the PyQGIS API label Apr 28, 2021
@nyalldawson nyalldawson self-assigned this May 18, 2021
nyalldawson added a commit to nyalldawson/QGIS that referenced this issue May 18, 2021
And also rename Qgis::MessageLevel::None to NoLevel. None is a reserved
keyword in Python, so this value was previously inaccessible to PyQGIS
scripts

Fixes qgis#42996
nyalldawson added a commit to nyalldawson/QGIS that referenced this issue May 19, 2021
And also rename Qgis::MessageLevel::None to NoLevel. None is a reserved
keyword in Python, so this value was previously inaccessible to PyQGIS
scripts

Fixes qgis#42996
nyalldawson added a commit to nyalldawson/QGIS that referenced this issue May 28, 2021
And also rename Qgis::MessageLevel::None to NoLevel. None is a reserved
keyword in Python, so this value was previously inaccessible to PyQGIS
scripts

Fixes qgis#42996
nyalldawson added a commit to nyalldawson/QGIS that referenced this issue May 29, 2021
keyword in Python, so this value was previously inaccessible to PyQGIS
scripts

Also change all references to Qgis::MessageLevel values to their
fully qualified names, to ease a future transition to an enum
class (when sip bugs are fixed)

Fixes qgis#42996
nyalldawson added a commit that referenced this issue May 30, 2021
keyword in Python, so this value was previously inaccessible to PyQGIS
scripts

Also change all references to Qgis::MessageLevel values to their
fully qualified names, to ease a future transition to an enum
class (when sip bugs are fixed)

Fixes #42996
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! PyQGIS Related to the PyQGIS API
Projects
None yet
3 participants