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 810271b commit 128c446
Show file tree
Hide file tree
Showing 3 changed files with 41 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 @@ -40,6 +40,7 @@ ignore =
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -121,6 +122,8 @@ ignore =
>>>>>>> c1a5635118 (g.proj: fix reading input WKT (#1582))
=======
>>>>>>> 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 @@ -146,6 +149,7 @@ ignore =
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> c1a5635118 (g.proj: fix reading input WKT (#1582))
=======
Expand Down Expand Up @@ -199,6 +203,9 @@ ignore =
=======
=======
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
=======
=======
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
=======
E722, # do not use bare 'except'
>>>>>>> 7e8f036e2d (pythonlib: Remove star imports (#1546))
Expand All @@ -216,6 +223,7 @@ ignore =
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 7e7871fd90 (g.proj: fix reading input WKT (#1582))
<<<<<<< HEAD
Expand Down Expand Up @@ -339,6 +347,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 @@ -349,6 +349,7 @@ def _run_test_module(self, module, results_dir, gisdbase, location, timeout):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -395,6 +396,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 @@ -412,6 +415,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 @@ -507,6 +511,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 @@ -941,6 +949,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 @@ -951,6 +960,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 @@ -994,6 +1007,7 @@ def try_decode(data, encodings):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -1024,6 +1038,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 @@ -1137,6 +1153,7 @@ def try_decode(data, encodings):
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> main
Expand Down Expand Up @@ -1274,6 +1291,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
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 @@ -46,6 +46,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> main
=======
Expand Down Expand Up @@ -432,6 +433,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 @@ -441,6 +444,8 @@
>>>>>>> 2bf163e4b3 (libpython: Save and load benchmark results (#1711))
=======
>>>>>>> dad8f82179 (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> 95adae2f53 (pythonlib: Remove star imports (#1546))
<<<<<<< HEAD
=======
>>>>>>> dad8f82179 (wxpyimgview: explicit conversion to int (#2704))
Expand Down Expand Up @@ -509,18 +514,23 @@
>>>>>>> 8422103f4c (wxpyimgview: explicit conversion to int (#2704))
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> dad8f82179 (wxpyimgview: explicit conversion to int (#2704))
<<<<<<< HEAD
>>>>>>> b5acd78515 (wxpyimgview: explicit conversion to int (#2704))
=======
=======
>>>>>>> dad8f82179 (wxpyimgview: explicit conversion to int (#2704))
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
=======
=======
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))
<<<<<<< HEAD
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
=======
>>>>>>> bdc1a9eff8 (pythonlib: Remove star imports (#1546))
Expand All @@ -534,6 +544,8 @@
=======
>>>>>>> dad8f82179 (wxpyimgview: explicit conversion to int (#2704))
>>>>>>> b5acd78515 (wxpyimgview: explicit conversion to int (#2704))
=======
>>>>>>> c5d3b09cb4 (pythonlib: Remove star imports (#1546))
from datetime import datetime
from multiprocessing import Lock, Pipe, Process

Expand Down

0 comments on commit 128c446

Please sign in to comment.