Message304372
OK, I'll head down the path of creating a new procedural PEP to supersede PEP 411 (I'll try to get the locals() semantic clarification PEP out of the way first, though).
I'll make "Where to put the feature flags?" an open question, as my rationale for proposing __main__ was three-fold:
1. In regular scripts, it makes feature flags as easy to set as possible, since you can just do "use_provisional_interpreters = True" without any import at all
2. In applications, "import __main__; use_provisional_interpreters = True" isn't markedly more brittle as a process-global state storage location than any other module name (as long as the feature flag names are prefixed to minimise the risk of name collisions)
3. Using an existing always imported module makes the runtime cost of managing the feature flags as close to zero as possible
However, you'd also get most of those benefits with an even lower risk of name collisions by co-opting "sys" for the same purpose.
Silencing the warning via the feature flag:
import sys
sys.use_provisional_interpreters = True
import interpreters
Silencing the warning via the warnings module:
from warnings import filterwarnings
filterwarnings("ignore", module="interpreters", category=FutureWarning)
import interpreters
Emitting the warning:
import sys
_feature_flag = f"use_provisional_{__name__}"
if not getattr(sys, _feature_flag):
import warnings
_provisional_msg = (
f"The {__name__} module is currently a provisional API - see documentation for details. "
f"Set 'sys.{_feature_flag} = True' before importing the API to disable this warning."
)
warnings.warn(FutureWarning, _provisional_msg) |
|
Date |
User |
Action |
Args |
2017-10-14 04:22:20 | ncoghlan | set | recipients:
+ ncoghlan, gvanrossum, ned.deily, habnabit, r.david.murray, eric.snow, serhiy.storchaka, dstufft, hawkowl |
2017-10-14 04:22:19 | ncoghlan | set | messageid: <1507954939.97.0.213398074469.issue31742@psf.upfronthosting.co.za> |
2017-10-14 04:22:19 | ncoghlan | link | issue31742 messages |
2017-10-14 04:22:17 | ncoghlan | create | |
|