E-SE0006 — Cannot parse the source of a decorated function

Error Type

Syntax Error

Phase

defining a problem with the decorator API

Python exception

ValueError (builtin)

Message

Cannot parse the source of the decorated function `{name}`: {error}

Positions are relative to the start of the function definition.

Possible fix: rewrite the function body using Python syntax supported by the decorator API.

({name} is the name of the decorated function; {error} is the parser’s description of what it could not parse, including the location)

Cause

The decorator API reads the source code of the decorated function and parses it before running it. This error is raised when that parse fails: the function’s source uses Python syntax the decorator API’s parser does not support, typically syntax introduced in a Python release newer than the supported grammar (for example def f[T](...) type-parameter lists). It can also happen when the source text recovered for the function is not parseable on its own.

Fix

Use the location and description in the {error} part of the message to find the offending construct, remembering that line and column numbers count from the start of the function definition, then rewrite it using syntax that also exists in earlier Python releases. Only the decorated function itself needs to avoid the unsupported syntax; the rest of your program is unaffected.