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 Jul 23, 2024
1 parent b92dc79 commit d7d1827
Show file tree
Hide file tree
Showing 3 changed files with 33 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 @@ -4,11 +4,17 @@ ignore =
W503, # line break before binary operator (Black)
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
E722, # do not use bare 'except'
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 7c10386e82 (g.proj: fix reading input WKT (#1582))
=======
=======
E722, # do not use bare 'except'
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 57aff3a06a (pythonlib: Remove star imports (#1546))

per-file-ignores =
# C wrappers call libgis.G_gisinit before importing other modules.
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 @@ -218,10 +218,13 @@ def _run_test_module(self, module, results_dir, gisdbase, location, timeout):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 6cf60c76a4 (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> 8422103f4c (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> 57aff3a06a (pythonlib: Remove star imports (#1546))
stdout = p.stdout
stderr = p.stderr
returncode = p.returncode
Expand Down Expand Up @@ -262,13 +265,18 @@ def _run_test_module(self, module, results_dir, gisdbase, location, timeout):
=======
stdout, stderr = p.communicate()
returncode = p.returncode
<<<<<<< HEAD
=======
>>>>>>> 6cf60c76a4 (wxpyimgview: explicit conversion to int (#2704))
encodings = [_get_encoding(), "utf8", "latin-1", "ascii"]
<<<<<<< HEAD
>>>>>>> 3fce2ed438 (pythonlib: Remove star imports (#1546))
=======
=======
encodings = [_get_encoding(), "utf8", "latin-1", "ascii"]
>>>>>>> 57aff3a06a (pythonlib: Remove star imports (#1546))
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
def try_decode(data, encodings):
"""Try to decode data (bytes) using one of encodings
Expand All @@ -281,6 +289,7 @@ def try_decode(data, encodings):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
return decode(data, encoding=encoding)
=======
Expand All @@ -295,6 +304,12 @@ def try_decode(data, encodings):
=======
return decode(data, encoding=encoding)
>>>>>>> 8422103f4c (wxpyimgview: explicit conversion to int (#2704))
=======
return decode(data, encoding=encoding)
=======
return decode(stdout, encoding=encoding)
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 57aff3a06a (pythonlib: Remove star imports (#1546))
except UnicodeError:
pass
if isinstance(data, bytes):
Expand Down
12 changes: 12 additions & 0 deletions python/grass/temporal/c_libraries_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
import sys
from ctypes import CFUNCTYPE, POINTER, byref, c_int, c_void_p, cast
=======
Expand All @@ -24,6 +25,8 @@
>>>>>>> 2bf163e4b3 (libpython: Save and load benchmark results (#1711))
=======
>>>>>>> dad8f82179 (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> 95adae2f53 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
from ctypes import byref, cast, c_int, c_void_p, CFUNCTYPE, POINTER
=======
Expand All @@ -47,7 +50,16 @@
=======
from ctypes import byref, cast, c_int, c_void_p, CFUNCTYPE, POINTER
>>>>>>> 8422103f4c (wxpyimgview: explicit conversion to int (#2704))
<<<<<<< HEAD
>>>>>>> dad8f82179 (wxpyimgview: explicit conversion to int (#2704))
=======
=======
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
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 57aff3a06a (pythonlib: Remove star imports (#1546))
>>>>>>> 95adae2f53 (pythonlib: Remove star imports (#1546))
from datetime import datetime
from multiprocessing import Lock, Pipe, Process

Expand Down

0 comments on commit d7d1827

Please sign in to comment.