[GRASS-git] [OSGeo/grass] 6669a4: Fix Flake8 errors in temporal modules (#573)

Vaclav Petras noreply at github.com
Thu May 7 18:39:48 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/OSGeo/grass
  Commit: 6669a4dc9ca5f6c77fef0945f0fce92caec1db19
      https://github.com/OSGeo/grass/commit/6669a4dc9ca5f6c77fef0945f0fce92caec1db19
  Author: Vaclav Petras <wenzeslaus at gmail.com>
  Date:   2020-05-07 (Thu, 07 May 2020)

  Changed paths:
    M temporal/.flake8
    M temporal/t.info/t.info.py
    M temporal/t.list/t.list.py
    M temporal/t.merge/t.merge.py
    M temporal/t.rast.accdetect/t.rast.accdetect.py
    M temporal/t.rast.accumulate/t.rast.accumulate.py
    M temporal/t.rast.algebra/t.rast.algebra.py
    M temporal/t.rast.gapfill/t.rast.gapfill.py
    M temporal/t.rast.what/t.rast.what.py
    M temporal/t.rast3d.algebra/t.rast3d.algebra.py
    M temporal/t.rast3d.mapcalc/t.rast3d.mapcalc.py
    M temporal/t.rename/t.rename.py
    M temporal/t.select/t.select.py
    M temporal/t.shift/t.shift.py
    M temporal/t.unregister/t.unregister.py
    M temporal/t.vect.algebra/t.vect.algebra.py
    M temporal/t.vect.observe.strds/t.vect.observe.strds.py

  Log Message:
  -----------
  Fix Flake8 errors in temporal modules (#573)

* Comparison to None should be 'if cond is not None:' (E711)
* Comparison to False should be 'if cond is False:' or 'if not cond:' (E712)
* Imported but unused (F401)
* Do not use bare 'except' (E722)

There is the same or similar code in several modules checking presence of ply which is now documented as unused and lines are ignored for Flake8. Catching failed test import of ply using ImportError not bare except.

In some cases, the `is` operator is used for comparison (`check is False`), while in almost all other `cases == False` is simply removed (`not check`). The goal is to make less assumptions about the values coming from the "check" function and in the check variable. When the function name and variable name are something like `is_ok()` and `ok`, then it is pretty clear the possible values are True and False. With check, as a reader of this code, it is not clear if `check == False` and `not check` are really the same, because check could be e.g. None if the check failed and the case should be handled in some other way. (Likely not the case here, but we are already using same tactics in GUI.) With `is_ok()` and `ok` it is safer to make the assumption about what the possible values are. Both `not check` and `check is False` are allowed, so using here whatever is safer and easier to review. Couple other places have `is False` where it is not clear that the expression is boolean.

The errors are now reordered: serious first, whitespace last.




More information about the grass-commit mailing list