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 d39f1af commit 92ab37e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/grass/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ignore =
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -107,6 +108,8 @@ ignore =
>>>>>>> osgeo-main
=======
>>>>>>> 9fb6588182 (g.proj: fix reading input WKT (#1582))
=======
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
=======
E722, # do not use bare 'except'
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
Expand All @@ -129,6 +132,7 @@ ignore =
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 95f198e1e0 (g.proj: fix reading input WKT (#1582))
=======
Expand Down Expand Up @@ -177,6 +181,9 @@ ignore =
=======
=======
>>>>>>> osgeo-main
=======
=======
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
=======
E722, # do not use bare 'except'
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
Expand All @@ -192,6 +199,7 @@ ignore =
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 7e7871fd90 (g.proj: fix reading input WKT (#1582))
<<<<<<< HEAD
Expand Down Expand Up @@ -297,6 +305,8 @@ ignore =
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 9fb6588182 (g.proj: fix reading input WKT (#1582))
=======
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))

per-file-ignores =
# C wrappers call libgis.G_gisinit before importing other modules.
Expand Down
19 changes: 19 additions & 0 deletions python/grass/gunittest/invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ def _run_test_module(self, module, results_dir, gisdbase, location, timeout):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -377,6 +378,8 @@ def _run_test_module(self, module, results_dir, gisdbase, location, timeout):
=======
>>>>>>> b5acd78515 (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> 6cf60c76a4 (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> 8422103f4c (wxpyimgview: explicit conversion to int (#2704))
Expand All @@ -392,6 +395,7 @@ def _run_test_module(self, module, results_dir, gisdbase, location, timeout):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 57aff3a06a (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
Expand Down Expand Up @@ -475,6 +479,10 @@ def _run_test_module(self, module, results_dir, gisdbase, location, timeout):
>>>>>>> bc7152a288 (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> b5acd78515 (wxpyimgview: explicit conversion to int (#2704))
=======
=======
>>>>>>> 57aff3a06a (pythonlib: Remove star imports (#1546))
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
stdout = p.stdout
stderr = p.stderr
returncode = p.returncode
Expand Down Expand Up @@ -865,6 +873,7 @@ 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"]
Expand All @@ -875,6 +884,10 @@ def _run_test_module(self, module, results_dir, gisdbase, location, timeout):
>>>>>>> f4b9197871 (pythonlib: Remove star imports (#1546))
=======
=======
=======
encodings = [_get_encoding(), "utf8", "latin-1", "ascii"]
>>>>>>> 57aff3a06a (pythonlib: Remove star imports (#1546))
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
>>>>>>> 3ced907ea6 (pythonlib: Remove star imports (#1546))
def try_decode(data, encodings):
Expand Down Expand Up @@ -913,6 +926,7 @@ def try_decode(data, encodings):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand All @@ -937,6 +951,8 @@ def try_decode(data, encodings):
>>>>>>> f4219c860c (libpython: Save and load benchmark results (#1711))
=======
>>>>>>> b5acd78515 (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
return decode(data, encoding=encoding)
=======
<<<<<<< HEAD
Expand Down Expand Up @@ -1047,6 +1063,7 @@ def try_decode(data, encodings):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> main
Expand Down Expand Up @@ -1161,6 +1178,8 @@ def try_decode(data, encodings):
return decode(data, encoding=encoding)
>>>>>>> 8422103f4c (wxpyimgview: explicit conversion to int (#2704))
>>>>>>> b5acd78515 (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
except UnicodeError:
pass
if isinstance(data, bytes):
Expand Down
17 changes: 17 additions & 0 deletions python/grass/temporal/c_libraries_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -421,6 +422,8 @@
>>>>>>> f4219c860c (libpython: Save and load benchmark results (#1711))
=======
>>>>>>> b5acd78515 (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
import sys
from ctypes import CFUNCTYPE, POINTER, byref, c_int, c_void_p, cast
=======
Expand All @@ -430,6 +433,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 Down Expand Up @@ -462,8 +467,20 @@
=======
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))
<<<<<<< HEAD
>>>>>>> b5acd78515 (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))
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
from datetime import datetime
from multiprocessing import Lock, Pipe, Process

Expand Down

0 comments on commit 92ab37e

Please sign in to comment.