Skip to content

SCR003: compile-warning

Jython compiles the script with a SyntaxWarning

Code SCR003
Name compile-warning
Category Scripts (SCR)
Default severity warning
Enabled by default yes
Fix available no
ign-lint equivalent none

Reports the code for which Jython 2.7's compiler issues a SyntaxWarning, with Jython's message. Verified against Ignition's Jython with full compilation, these are all of them:

  • name 'x' declared global after assignment: a global statement names a name that the same function, class body or module binds earlier in the source (an assignment, augmented assignment, del, import, def, class, for, with or except target, a list comprehension variable), whatever the control flow;
  • name 'x' declared global after use: otherwise, the same scope reads the name earlier (also as the object of an attribute or item assignment, and in decorators, default values, base classes and the first iterable of a generator expression). Uses in nested functions and classes, and uses after an earlier global of the name, do not count;
  • import * only allowed at module level: from m import * in a function or a method, or in a class inside a function. In Perspective and event scripts every import * is in a function (the script is the body of a generated function).

Where Jython refuses to compile the code anyway (SCR002), only the error is reported.

The global statement applies to the whole function, also to the code before it: the earlier assignment or read already used the global variable, which is rarely what the order suggests. import * in a function makes its names unknown to the compiler; Jython then looks every name up by name at run time, and nested functions that use free variables make it an error (SCR002). The warnings also end up in the gateway or client log each time the script is compiled.

def resetCounter():
counter = 0
global counter

Use instead:

def resetCounter():
global counter
counter = 0

Generated from the rule metadata by iglint generate-docs; iglint rule SCR003 prints the same page in the terminal. Source: docs/rules/SCR003.md.