The feature gating mechanism does not need to mirror Rust exactly. Criteria we want to support include:
Define a way to demarcate modules, classes, methods, and variables as experimental. Access to experimental capabilities is controlled by PyTeal release version. Only non-final (e.g. nightly builds, branch builds) versions can access experimental capabilities.
feature_gates.FeatureGates provides a mechanism for defining global booleans that are loaded before the rest of PyTeal is. An experimental code path could directly use these globals via FeatureGates.theFeature_isOn() or I can also imagine a decorator such as @FeatureGate.decorate_theFeature_isOn which actually runs an assert FeatureGates.theFeature_isOn() as part of the wrapped method. To avail the feature in a particular build, one could call FeatureGate.set_theFeature_isOn(True) and to officially release (without removing the decorators) is as simple as changing FeatureGates.DEFAULTS.theFeature_isOn
Optionally, providing an explicit opt-in mechanism to use experimental features.
That's available via -for example- FeatureGate.set_theFeature_isOn(True)
Addressing the pyteal.ini portion of https://github.com/algorand/pyteal/issues/677 as well as proposing a way to address https://github.com/algorand/pyteal/issues/601
Please see
examples/applications/sourcemap.py
for usage example.Regarding Feature Gates Issue 601
re-quoting that issue:
feature_gates.FeatureGates
provides a mechanism for defining global booleans that are loaded before the rest of PyTeal is. An experimental code path could directly use these globals viaFeatureGates.theFeature_isOn()
or I can also imagine a decorator such as@FeatureGate.decorate_theFeature_isOn
which actually runs anassert FeatureGates.theFeature_isOn()
as part of the wrapped method. To avail the feature in a particular build, one could callFeatureGate.set_theFeature_isOn(True)
and to officially release (without removing the decorators) is as simple as changingFeatureGates.DEFAULTS.theFeature_isOn
That's available via -for example-
FeatureGate.set_theFeature_isOn(True)