genie_python script checking (linting)

On g.load_script genie_python now runs pylint on the scripts. This help the user see errors before the script is run. However sometimes this causes its own issues. There is a page in the user manual describing what the user should do.

If a warning cannot be fixed, and you are sure the code is otherwise correct, warnings can be ignored from a line by adding a comment:

some_code()  # pylint disable=<warning name>

For example:

from IMAT_library import *  # pylint: disable=wildcard-import, unused-wildcard-import

If the error is a pyright (typing) error, as opposed to a pylint error, then the comment syntax is:

some_code()  # pyright: ignore

Linting dynamically defined variables

Python allows programmers to set attributes dynamically using expressions like locals()['foo'] = 1, which creates a local variable called foo with value 1. Pylint doesn’t support dynamic assignment, so if foo was subsequently referenced in the code it would be counted as an undefined variable.

In cases where we need to lint scripts containing dynamic assignments, we can write a Pylint transform plugin to let Pylint know that the dynamically assigned variables are OK and should not be counted as undefined. This has been done here to support dynamic assignments in the SCANS library, where some scripts were dynamically adding all methods of classes derived from ScanningInstrument to the local module.