This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients dstufft, eric.snow, gvanrossum, habnabit, hawkowl, ncoghlan, ned.deily, r.david.murray, serhiy.storchaka
Date 2017-10-14.04:22:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1507954939.97.0.213398074469.issue31742@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2017-10-14 04:22:20ncoghlansetrecipients: + ncoghlan, gvanrossum, ned.deily, habnabit, r.david.murray, eric.snow, serhiy.storchaka, dstufft, hawkowl
2017-10-14 04:22:19ncoghlansetmessageid: <1507954939.97.0.213398074469.issue31742@psf.upfronthosting.co.za>
2017-10-14 04:22:19ncoghlanlinkissue31742 messages
2017-10-14 04:22:17ncoghlancreate