SCR101: undefined-name
Name is not defined anywhere the script can see
| Code | SCR101 |
| Name | undefined-name |
| Category | Scripts (SCR) |
| Default severity | error |
| Enabled by default | yes |
| Fix available | no |
| ign-lint equivalent | none |
What it does
Section titled “What it does”Reports names that are bound nowhere the code can see them: not in the function, not in an enclosing function, not at module level, not a Jython builtin and not one of the names Ignition provides to the script.
Ignition provides, without import (verified on an 8.3 gateway):
system, fpmi (legacy alias of system), sys, __builtins__, the
generated function's own name, and every top-level package or module of
the project's script library (core for core/util/code.py), including
those of child projects when the script belongs to an inheritable project.
Library modules also have __name__ (and __package__ once an import has
run), but not __file__.
The scoping rules are Python 2.7's: list comprehension variables leak into the enclosing scope, generator expressions do not; names bound in a class body are not visible to its methods.
The rule stays silent where it cannot be sure: in scopes with from x import * or unqualified exec; in a module that writes its own namespace
(exec code in globals(), also in d, globals(), globals()['x'] = ...,
globals().update(...), setattr(sys.modules[__name__], ...),
sys.modules[__name__].x = ...) or the builtins (__builtins__['x'] = ...,
setattr(__builtin__, ...), __builtin__.x = ...); in a function that runs
exec code in locals() (or in vars(), in globals(), locals()), whose
names Jython looks up at run time; inside a try
whose handlers catch NameError, in projects whose parent project is not
part of the linted tree (its library is unknown), and for the 7.x prefixes
project., shared. and app. (reported by SCR206).
Not checked at all: a .py file outside any project (no project.json in
its directory or a parent directory, such as a loose file linted on its
own) and the tag scripts of gateway resources. Any name they do not
bind could be a top-level package of the script library they run with,
which iglint does not know there, so no name is reported, not only names
that look like packages. Lint the file as part of its project to check it.
Why is this bad?
Section titled “Why is this bad?”The script raises NameError when it reaches the name. In a Perspective
event that means the action silently does nothing but log an error; in a
transform the binding gets an error quality.
Example
Section titled “Example”def runAction(self, event): rows = system.db.runNamedQuery("Lines/All") for row in rows: lineName = row["name"] self.view.custom.last = linenameUse instead:
def runAction(self, event): rows = system.db.runNamedQuery("Lines/All") for row in rows: lineName = row["name"] self.view.custom.last = lineNamepylint
Section titled “pylint”Corresponds to E0602 undefined-variable. Differences, all because pylint
assumes CPython 3: pylint reports system, the project's library packages
and the header parameters of Perspective scripts (iglint knows them), and
reports list comprehension variables used after the comprehension (they
leak in Jython 2.7). pylint does not report __file__ in library modules,
which Ignition does not define.
Generated from the rule metadata by iglint generate-docs; iglint rule SCR101 prints the same page in the terminal. Source: docs/rules/SCR101.md.