Python Editor Features

The Autonomy Edge IDE provides a rich editing experience for Python function blocks. You get syntax highlighting, type checking, autocompletion, hover documentation, and code snippets. All running directly in your browser.

Editor Overview

When you open a Python function block in the IDE, the code editor provides:

  • Python-specific syntax highlighting
  • Pyright-based type checking and intelligent features
  • A curated set of code snippets for common Python patterns
  • Automatic indentation and bracket matching

The result is a modern editing experience where you can write, validate, and refine your Python code without leaving the browser.

Syntax Highlighting

The Python syntax highlighter provides color-coded highlighting for:

  • Keywords: def, class, if, elif, else, for, while, try, except, import, from, return, global, with, as, yield, lambda, etc.
  • Built-in functions: print(), len(), range(), int(), float(), str(), list(), dict(), tuple(), set(), type(), isinstance(), etc.
  • Operators: Arithmetic (+, -, *, /, //, %, **), comparison (==, !=, <, >, <=, >=), logical (and, or, not), bitwise (&, |, ^, ~, <<, >>)
  • Strings: Single-quoted, double-quoted, triple-quoted, and raw strings (r-strings)
  • Numbers: Integers, floats, hex (0x), octal (0o), binary (0b), and scientific notation
  • Comments: Lines starting with #
  • Decorators: Lines starting with @

Syntax highlighting activates immediately as you type. No delay or configuration required.

Type Checking and Diagnostics

The IDE integrates Pyright, a fast static type checker for Python, running directly in your browser. Pyright analyzes your code for type errors, undefined variables, incorrect function signatures, and other issues. Diagnostics appear as underlined warnings or errors in the editor, with details shown when you hover over the underlined code.

Examples of issues Pyright can detect:

  • Using an undefined variable name
  • Passing the wrong number of arguments to a function
  • Type mismatches (e.g., adding a string to an integer)
  • Missing return statements in functions with declared return types
  • Unreachable code after return or raise

Diagnostics are refreshed approximately every 1 second after you stop typing, so feedback is near-instantaneous without being disruptive.

Hover Documentation

When you hover your mouse over a variable, function, or module name, the editor displays a tooltip with:

  • The inferred type of the symbol
  • The function signature (for functions and methods)
  • The docstring (for standard library functions and classes)

This is especially handy for standard library modules. Hover over a function like math.sin or json.loads and you'll see its signature and docstring without leaving the editor.

Autocompletion

As you type, the editor suggests completions based on:

  • Python keywords and built-in functions
  • Variables and functions defined in your code
  • Module members after an import (e.g., typing math. shows sin, cos, sqrt, pi, etc.)
  • Method names on objects (e.g., typing my_list. shows append, extend, sort, etc.)

Press Tab or Enter to accept a suggestion, or Escape to dismiss the completion list.

Feature Summary

FeatureStatusDescription
Syntax highlightingEnabledColor-coded tokens as you type
Hover documentationEnabledType info and docstrings on mouse hover
AutocompletionEnabledContext-aware suggestions as you type
DiagnosticsEnabledType errors and warnings, refreshed every ~1 second
Signature helpDisabledNo inline parameter hints during function calls
Rename symbolDisabledNo cross-file rename refactoring
Go to definitionDisabledNo jump-to-definition navigation

The disabled features are not applicable in the single-file context of Python function blocks, where each FB is a standalone script.

Code Snippets

The editor includes code snippets for common Python patterns. Type a snippet prefix and select it from the completion list to insert a pre-formatted code template with placeholder fields you can tab through.

PrefixExpands To
ifif statement with condition and body
elifelif clause
elseelse clause
if/elseComplete if/else block
if/elif/elseComplete if/elif/else block
forfor loop with iterable
whilewhile loop with condition
try/excepttry/except block
try/except/finallytry/except/finally block
try/except/else/finallyFull try block with all clauses
defFunction definition with parameters and body
classClass definition with __init__ method
withwith statement (context manager)
listList comprehension
dictDictionary comprehension
lambdaLambda expression

To use a snippet:

  1. Start typing the snippet prefix (e.g., for)
  2. Select the snippet from the autocompletion dropdown
  3. The template is inserted with the first placeholder selected
  4. Press Tab to move to the next placeholder
  5. Press Escape when done editing placeholders

Example: Using the for Snippet

Type for and select the snippet. The editor inserts:

python
for item in iterable: pass

With item selected as the first placeholder. Type your variable name, press Tab to jump to iterable, type your collection name, then Tab again to move into the loop body.

Tips for Effective Editing

Use Type Hints for Better Diagnostics

While not required, adding type hints to your own helpers and locals helps Pyright provide more accurate diagnostics:

python
def clamp(value: float, lo: float, hi: float) -> float: if value < lo: return lo if value > hi: return hi return value def block_init() -> None: global sample_count sample_count = 0 def block_loop() -> None: global sample_count, average sample_count += 1 average = clamp(reading / sample_count, 0.0, 100.0)

Check Diagnostics Before Building

The diagnostics panel catches many errors that would otherwise surface only at build time or at runtime. Before building your project, check that there are no red (error) underlines in your Python code. Yellow (warning) underlines are worth reviewing but don't necessarily indicate problems.

Use Print Statements for Debugging

The print() function is available and its output is captured by the runtime's logging system. During development, use print statements to confirm that input values look right and to inspect what your code is producing for outputs:

python
def block_loop(): global result print(f'Raw input value: {raw}') # Visible in runtime logs result = raw * 2 print(f'Output value: {result}')

Tip: Remove or comment out verbose print statements before deploying to production to reduce logging overhead.

Leverage Autocompletion for Imports

When you need a standard library module, type import and the autocompletion list shows available modules:

python
import math # Mathematical functions import json # JSON encoding/decoding import datetime # Date and time handling import re # Regular expressions import statistics # Statistical functions

What's Next?

Continue to C++ Function Blocks to learn about the other custom programming language available for extending PLC functionality with C++ code, including direct hardware access via Arduino-compatible APIs.