Nick Coghlan <[email protected]> added the comment:
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)
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue31742>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com