[GRASS-git] [OSGeo/grass] 47aa6e: Modernize Python syntax, resolves Python 3.12 `\.`...
Edouard Choinière
noreply at github.com
Wed Jan 3 07:08:13 PST 2024
Branch: refs/heads/main
Home: https://github.com/OSGeo/grass
Commit: 47aa6e13ce62076f77dcb4cadb452ca6a57a00c6
https://github.com/OSGeo/grass/commit/47aa6e13ce62076f77dcb4cadb452ca6a57a00c6
Author: Edouard Choinière <27212526+echoix at users.noreply.github.com>
Date: 2024-01-03 (Wed, 03 Jan 2024)
Changed paths:
M display/d.text/test.py
M doc/gui/wxpython/example/frame.py
M gui/wxpython/animation/frame.py
M gui/wxpython/core/globalvar.py
M gui/wxpython/core/layerlist.py
M gui/wxpython/core/render.py
M gui/wxpython/gcp/mapdisplay.py
M gui/wxpython/gui_core/menu.py
M gui/wxpython/gui_core/preferences.py
M gui/wxpython/gui_core/prompt.py
M gui/wxpython/gui_core/simplelmgr.py
M gui/wxpython/iclass/frame.py
M gui/wxpython/image2target/ii2t_mapdisplay.py
M gui/wxpython/iscatt/iscatt_core.py
M gui/wxpython/lmgr/frame.py
M gui/wxpython/location_wizard/wizard.py
M gui/wxpython/main_window/frame.py
M gui/wxpython/mapdisp/frame.py
M gui/wxpython/mapswipe/frame.py
M gui/wxpython/mapwin/decorations.py
M gui/wxpython/photo2image/ip2i_mapdisplay.py
M gui/wxpython/psmap/instructions.py
M gui/wxpython/rlisetup/sampling_frame.py
M gui/wxpython/web_services/cap_interface.py
M lib/init/grass.py
M man/parser_standard_options.py
M python/grass/pydispatch/dispatcher.py
M python/grass/pygrass/gis/__init__.py
M python/grass/pygrass/messages/__init__.py
M python/grass/pygrass/modules/grid/grid.py
M python/grass/pygrass/modules/interface/parameter.py
M python/grass/pygrass/modules/testsuite/test_import_isolation.py
M python/grass/pygrass/tests/benchmark.py
M python/grass/script/vector.py
M python/grass/temporal/datetime_math.py
M scripts/r.in.wms/wms_cap_parsers.py
M scripts/r.in.wms/wms_drv.py
M scripts/v.rast.stats/v.rast.stats.py
M temporal/t.rast.aggregate/testsuite/test_aggregation_absolute_parallel.py
Log Message:
-----------
Modernize Python syntax, resolves Python 3.12 `\.` Syntax warning (#3316)
* Fix unnecessary future import
See
https://docs.astral.sh/ruff/rules/unnecessary-future-import/ https://github.com/asottile/pyupgrade?tab=readme-ov-file#__future__-import-removal
* python: Fix remaining useless object inheritance
See https://docs.astral.sh/ruff/rules/useless-object-inheritance/
* Fix some checks of type, where the type is already a primitive.
See https://docs.astral.sh/ruff/rules/type-of-primitive/
* Fix remaining check of type of primitive.
Might need a second look to make sure the message protocol handled strings correctly. The check was different than others.
See https://docs.astral.sh/ruff/rules/type-of-primitive/
* Fix unnecessary calls to functions instead of native literals
See https://docs.astral.sh/ruff/rules/native-literals/
* Use generator expressions when list comprehension is immediately unpacked.
See https://docs.astral.sh/ruff/rules/unpacked-list-comprehension/
* Use builtin open instead of python3' alias io.open
See https://docs.astral.sh/ruff/rules/open-alias/
* Use `yield from` when a simple yield in a for loop is used. Supported since Python 3.3.
See https://docs.astral.sh/ruff/rules/yield-in-for-loop/
* Convert additional `yield` usage inside a list to a `yield from`
* Removed extra parentheses where obviously unneeded
Some other cases were flagged and could have been automatically fixed, but I wasn't confident enough to apply them now.
See https://docs.astral.sh/ruff/rules/extraneous-parentheses/
* Removed extra parentheses in `.BestSize((self.xx.GetBestSize()))` calls
Some existing calls already called it without the extra parentheses. From the wxPython docs, I understand that GetBestSize returns a wx.Size object, and the BestSize() can accept wx.size, a tuple of (x,y), or two arguments, like x and y separately (at least for https://docs.wxpython.org/wx.lib.agw.aui.framemanager.AuiPaneInfo.html?highlight=bestsize#wx.lib.agw.aui.framemanager.AuiPaneInfo.BestSize)
* Removed a Python 2.6 version block for json.loads kwargs
See https://docs.astral.sh/ruff/rules/outdated-version-block/
* Use raw strings when using `\.`
The sequence `\.` is an undefined escape sequence, but can be found in regex-strings. In regex strings, we usually want the backslash character and the dot character, instead of escaping dot like if it was a tab character `\t`. This is what raw strings (strings prefixed with r) do: they treat backslashes as literal characters.
In Python 3.12, using `\.` in a string (not raw strings) raises `SyntaxWarning: invalid escape sequence '\.'`
* Apply suggestion from code review
* Revert "Convert additional `yield` usage inside a list to a `yield from`"
This reverts commit 3b2bb8c8b60435f8163bebda23c255fad91876b7.
More information about the grass-commit
mailing list