Class PythonParameterDefaultValueProvider

java.lang.Object
io.micronaut.python.processing.PythonParameterDefaultValueProvider
All Implemented Interfaces:
Ordered, ParameterDefaultValueProvider

public final class PythonParameterDefaultValueProvider extends Object implements ParameterDefaultValueProvider
Supplies the declared default value of a Python parameter, where that default is an immutable literal the generated code can reproduce.

A Python default is evaluated by the interpreter, so in general it is applied by the stub constructor rather than by the caller. A literal is the exception: host: str = "localhost" carries its value into ArgumentDef#defaultValue() at compile time, so it can be passed explicitly and is indistinguishable from letting Python apply it.

Anything else — a mutable literal, a default_factory (an DefaultFactoryDef), a call, a name — yields Optional.empty(), leaving those parameters to the stub's own defaulting. In particular a fresh mutable default must not be materialised here, as Python evaluates a mutable default once at definition time and shares it between calls.

Since:
5.2.0
Author:
graemerocher
  • Constructor Details

    • PythonParameterDefaultValueProvider

      public PythonParameterDefaultValueProvider()
  • Method Details