Skip to content

Commit

Permalink
pythonlib: Remove star imports (OSGeo#1546)
Browse files Browse the repository at this point in the history
Replaces star import (from x import *) by regular imports (from x import y).

Enables the relevant Flake8 warnings.

Adds the warning to per-file ignores for init files where we expect and allow
using star imports (unfortunately some init files contain actual code suffers
from these warning being disabled, but that's a different issue).
  • Loading branch information
a0x8o committed Sep 5, 2024
1 parent bf33eef commit fc0cb3e
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/grass/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ignore =
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -285,6 +286,11 @@ ignore =
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 460748a7fb (g.proj: fix reading input WKT (#1582))
=======
=======
E722, # do not use bare 'except'
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))

per-file-ignores =
# C wrappers call libgis.G_gisinit before importing other modules.
Expand Down
6 changes: 6 additions & 0 deletions python/grass/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self, module, code, returncode, errors=None):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
Expand Down Expand Up @@ -168,6 +169,11 @@ def __init__(self, module, code, returncode, errors=None):
=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
if not module or module in code:
# No need to include module name if it is directly in code
# of if it is not set.
Expand Down
15 changes: 15 additions & 0 deletions python/grass/gunittest/invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,14 @@ def _run_test_module(self, module, results_dir, gisdbase, location, timeout):
returncode = p.returncode
encodings = [_get_encoding(), "utf8", "latin-1", "ascii"]
<<<<<<< HEAD
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
=======
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
def try_decode(data, encodings):
"""Try to decode data (bytes) using one of encodings

Expand Down Expand Up @@ -858,6 +864,7 @@ def try_decode(data, encodings):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -1001,13 +1008,16 @@ def try_decode(data, encodings):
>>>>>>> 3ab33fc0b6 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 4fa4b4b8fe (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
return decode(data, encoding=encoding)
=======
return decode(stdout, encoding=encoding)
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> 0bd7d818a8 (pythonlib: Remove star imports (#1546))
=======
=======
Expand Down Expand Up @@ -1085,6 +1095,11 @@ def try_decode(data, encodings):
return decode(stdout, encoding=encoding)
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
=======
return decode(stdout, encoding=encoding)
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
except UnicodeError:
pass
if isinstance(data, bytes):
Expand Down
6 changes: 6 additions & 0 deletions python/grass/script/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
Expand Down Expand Up @@ -115,6 +116,11 @@
=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))

import os
from .core import (
Expand Down
6 changes: 6 additions & 0 deletions python/grass/script/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
=======
Expand Down Expand Up @@ -61,6 +62,8 @@
>>>>>>> osgeo-main
=======
>>>>>>> osgeo-main
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))

=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
Expand All @@ -77,6 +80,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> main
Expand Down Expand Up @@ -127,6 +131,8 @@
=======
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
import os
import re
import sys
Expand Down
7 changes: 7 additions & 0 deletions python/grass/script/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD

from grass.exceptions import CalledModuleError, ScriptError
=======
Expand Down Expand Up @@ -79,13 +80,17 @@
=======
>>>>>>> 4fa4b4b8fe (pythonlib: Remove star imports (#1546))
=======
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
=======

from grass.exceptions import CalledModuleError, ScriptError
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> 5fb05831cc (pythonlib: Remove star imports (#1546))
=======
>>>>>>> osgeo-main
Expand Down Expand Up @@ -132,6 +137,8 @@
=======
=======
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))

from grass.exceptions import CalledModuleError, ScriptError
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
Expand Down
14 changes: 14 additions & 0 deletions python/grass/temporal/c_libraries_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -412,16 +413,29 @@
=======
>>>>>>> osgeo-main
=======
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
import sys
from ctypes import CFUNCTYPE, POINTER, byref, c_int, c_void_p, cast
=======
=======
>>>>>>> 56010eb999 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
from ctypes import byref, cast, c_int, c_void_p, CFUNCTYPE, POINTER
=======
from ctypes import byref, cast, c_char_p, c_int, c_void_p, CFUNCTYPE, POINTER
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
>>>>>>> bdc1a9eff8 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
=======
=======
from ctypes import byref, cast, c_char_p, c_int, c_void_p, CFUNCTYPE, POINTER
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 56010eb999 (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
from datetime import datetime
from multiprocessing import Lock, Pipe, Process

Expand Down
5 changes: 5 additions & 0 deletions python/grass/temporal/temporal_granularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
Expand Down Expand Up @@ -160,7 +161,11 @@
=======
>>>>>>> osgeo-main
=======
=======
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
from functools import reduce
from collections import OrderedDict
>>>>>>> bdc1a9eff8 (pythonlib: Remove star imports (#1546))
Expand Down

0 comments on commit fc0cb3e

Please sign in to comment.