[GRASS-git] [OSGeo/grass] ad0799: Code quality fixes for grass package (lib/python) ...

Vaclav Petras noreply at github.com
Sun May 3 15:49:26 PDT 2020


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

  Changed paths:
    M lib/python/.flake8
    M lib/python/ctypes/ctypesgencore/parser/cgrammar.py
    M lib/python/ctypes/ctypesgencore/parser/pplexer.py
    M lib/python/gunittest/checkers.py
    M lib/python/gunittest/multireport.py
    M lib/python/imaging/images2swf.py
    M lib/python/pygrass/modules/grid/grid.py
    M lib/python/pygrass/raster/abstract.py
    M lib/python/pygrass/rpc/__init__.py
    M lib/python/pygrass/vector/abstract.py
    M lib/python/pygrass/vector/table.py
    M lib/python/pygrass/vector/testsuite/test_table.py
    M lib/python/script/core.py
    M lib/python/script/raster.py
    M lib/python/script/task.py
    M lib/python/script/utils.py
    M lib/python/temporal/core.py
    M lib/python/temporal/space_time_datasets.py

  Log Message:
  -----------
  Code quality fixes for grass package (lib/python) (#576)

This PR fixes Flake8 errors/warnings:

* Do not assign a lambda expression, use a def (E731)
* 'raise NotImplemented' should be 'raise NotImplementedError' (F901)
* Redefinition of unused...from line... (F811)
* Do not compare types, use 'isinstance()' (E721)
* Module level import not at top of file (E402)

And additionally it unifies checks for Python 3 using sys.version_info.major.

I also moved serious errors to be resolved up in the Flake8 configuration file and whitespace errors down. Details on some of the fixes follow.

Module level import: Fixing by actually moving imports (hashlib) and moving the non-importing code down after the imports (matplotlib.use and Python 2/3 variables). Several files ignored using the per-file-ignores. These may or may not be substantiated as exceptions, so keeping them in the config file rather than in the file itself to have here a clear warning that the check was disabled. However, in general, E402 should be fixable by moving code around and couple inline ignores like in the case of matplotlib.use in gunittest/multireport.

sys.version_info.major: Now all checks for Python 3 which are using sys.version_info.major are using >= operator because we are actually interested in 'not Python 2' and we assume Python 4 will behave more like Python 3 and not like Python 2.

Redefinition of unused...from line... seems to mostly report things imported twice in our case.

NotImplemented versus NotImplementedError:  NotImplemented is a constant for implementing binary special methods. NotImplementedError is an exception indicating real implementation still needs to be added.

Lambdas versus defs: Lambdas are for embedding into larger expressions. When assigned,
it is just a strange syntax for a function definition because def can appear anywhere in the code already.




More information about the grass-commit mailing list