Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PendingDeprecationWarning for % formatting #47021

Closed
ericvsmith opened this issue May 6, 2008 · 16 comments
Closed

Add PendingDeprecationWarning for % formatting #47021

ericvsmith opened this issue May 6, 2008 · 16 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@ericvsmith
Copy link
Member

BPO 2772
Nosy @rhettinger, @amauryfa, @ericvsmith, @benjaminp
Files
  • percent_formatting_pending_deprecation.diff
  • percent_formatting_pending_deprecation_0.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2009-01-06.10:00:13.534>
    created_at = <Date 2008-05-06.14:14:09.450>
    labels = ['interpreter-core']
    title = 'Add PendingDeprecationWarning for % formatting'
    updated_at = <Date 2009-01-06.10:00:13.526>
    user = 'https://github.com/ericvsmith'

    bugs.python.org fields:

    activity = <Date 2009-01-06.10:00:13.526>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-01-06.10:00:13.534>
    closer = 'rhettinger'
    components = ['Interpreter Core']
    creation = <Date 2008-05-06.14:14:09.450>
    creator = 'eric.smith'
    dependencies = []
    files = ['10202', '10232']
    hgrepos = []
    issue_num = 2772
    keywords = ['patch']
    message_count = 16.0
    messages = ['66313', '66314', '66316', '66333', '66337', '66338', '66346', '66350', '66361', '66365', '66384', '66466', '70003', '70007', '79230', '79243']
    nosy_count = 5.0
    nosy_names = ['nnorwitz', 'rhettinger', 'amaury.forgeotdarc', 'eric.smith', 'benjamin.peterson']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue2772'
    versions = ['Python 2.6', 'Python 3.0']

    @ericvsmith
    Copy link
    Member Author

    Per http://mail.python.org/pipermail/python-3000/2008-April/013094.html,
    add a PendingDeprecationWarning to 3.0 for % formatting.

    The attached patch implements this for 3.0. For 2.6, it should only be
    a PendingDeprecationWarning if -3 warnings are turned on. I'll work on
    that after the 3.0 patch is accepted.

    I'm not wild about using a global variable to disallow recursion, but
    it's probably the way to go. Question: Do I need to acquire the GIL here?

    Another issue is that the interpreter should probably at least start up
    without triggering these warnings. I'll add an issue for that at a
    later date.

    @ericvsmith ericvsmith added the easy label May 6, 2008
    @ericvsmith ericvsmith self-assigned this May 6, 2008
    @ericvsmith ericvsmith added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label May 6, 2008
    @amauryfa
    Copy link
    Member

    amauryfa commented May 6, 2008

    Do I need to acquire the GIL here?
    No, the GIL has already been acquired.

    The problem with the static variable is that while the main thread is
    PyErr_WarnEx(), another thread may gain focus. And it will not trigger
    the warning.

    @ericvsmith
    Copy link
    Member Author

    Right. But is it worth adding per-thread machinery to this? I was
    going to do that, but it seemed like overkill. Upon further reflection,
    however, I think you may be right.

    I'll remove the "easy" keyword!

    @ericvsmith ericvsmith removed the easy label May 6, 2008
    @benjaminp
    Copy link
    Contributor

    Would it be practical to add a _PyErr_InErrorProcessing function to
    prevent recursion?

    @ericvsmith
    Copy link
    Member Author

    Since we're just trying to prevent this function from recursing
    (indirectly) into itself, I think all of the logic can go here.

    What would you suggest the function _PyErr_InErrorProcessing do differently?

    I think the real issue is: Does the additional logic and execution time
    involved in adding per-thread state justify being "more correct", or can
    we occasionally lose a warning message?

    @benjaminp
    Copy link
    Contributor

    On Tue, May 6, 2008 at 4:50 PM, Eric Smith <report@bugs.python.org> wrote:

    Eric Smith <eric@trueblade.com> added the comment:

    Since we're just trying to prevent this function from recursing
    (indirectly) into itself, I think all of the logic can go here.

    What would you suggest the function _PyErr_InErrorProcessing do differently?

    I was just thinking that this problem would probably come up again.

    I think the real issue is: Does the additional logic and execution time
    involved in adding per-thread state justify being "more correct", or can
    we occasionally lose a warning message?

    Well, the first thing to check for is Py_Py3kWarning. Then do the
    extra logic and execution speed.

    @ericvsmith
    Copy link
    Member Author

    Well, the first thing to check for is Py_Py3kWarning. Then do the
    extra logic and execution speed.

    In 3.0, it's always a PendingDeprecationWarning, so that won't work.
    The test needs to be:

    if not recursing and warning_is_not_suppressed:
        warn()

    The recursion test is expensive if using thread local storage; the
    warning suppressed test looks expensive, too. So there's no quick short
    circuit test that I see. Of course all of this is just hot air until
    coded and benchmarked. I'll cook up a patch, but it will probably not
    be ready before the next alpha releases.

    @nnorwitz
    Copy link
    Mannequin

    nnorwitz mannequin commented May 7, 2008

    Why not use the normal recursion check mechanism? Specifically,

           if (Py_EnterRecursiveCall("unicode % "))
                    return NULL;
           // err = Warn();
           Py_LeaveRecursiveCall();

    I don't see where the problem with threads comes in. The GIL is held
    and shouldn't be released during this call. That may not be quite true
    (it's conceivable the GIL is released when warning). I'm not sure what
    happens with the I/O system at this point, it's possible that releases
    the GIL. However, if GIL is released and re-acquired in PyWarn_WarnEx()
    there are probably bigger issues than this patch that will need to be
    addressed. Note that since the warnings module is now implemented in C,
    this should be easier to deal with.

    Using the macros above in essence uses TLS, but through Python's
    PyThreadState.

    @ericvsmith
    Copy link
    Member Author

    I'm not sure Py_EnterRecursiveCall is what I want, because that allows
    the recursion to happen, but just aborts it when it gets too deep. What
    I want to achieve is to have the warning not called if it's the warning
    that's being formatted. I coded this up and couldn't get it to do the
    right thing.

    I think a better approach will be to remove % formatting from
    warnings.py. I think that will remove the need for any checks at all.
    I'll investigate that.

    @benjaminp
    Copy link
    Contributor

    On Wed, May 7, 2008 at 10:33 AM, Eric Smith <report@bugs.python.org> wrote:

    I think a better approach will be to remove % formatting from
    warnings.py. I think that will remove the need for any checks at all.
    I'll investigate that.

    That would make user code warning that uses '%"' brittle. However, if
    we warn about it, I think it's ok.

    @ericvsmith
    Copy link
    Member Author

    That would make user code warning that uses '%"' brittle. However, if
    we warn about it, I think it's ok.

    True enough. Then I think we should go with:

    1. Use .format() in the warnings module.
    2. Tell the users not to use % formatting in user code for warnings.
    3. Add my original, simple, global check for recursion. It will work
      incorrectly in an insignificant number of cases, and will typically
      result in at least one warning about % formatting, anyway.

    I'll have a patch ready soon.

    @ericvsmith
    Copy link
    Member Author

    The attached patch (percent_formatting_pending_deprecation_0.diff) adds
    both the simple global lock to unicode_mod() and changes warnings.py to
    use .format() instead of % formatting.

    I think this is good enough. We should add a warning to the docs saying
    user code used for warnings should also avoid % formatting. The only
    problem they'll see, however, is dropping an occasional warning in a
    multi-threaded app. But I'm not sure yet exactly where this mention
    would go.

    I also don't have any tests for this. I haven't found a test of a
    PendingDeprecationWarning.

    The biggest problem is that this patch breaks test_doctest with
    "RuntimeError: dictionary changed size during iteration". I've tried to
    find out why, but so far it escapes me. If someone else could look at
    the issue, I'd appreciate it.

    @ericvsmith ericvsmith removed their assignment Jul 19, 2008
    @rhettinger
    Copy link
    Contributor

    I think this is premature until be know for sure that % formatting will
    in-fact be deprecated in Py3.1. Time will tell how well the new format
    options get accepted. Likewise, we'll learn more about how readily
    legacy code can get converted.

    Guido, can you pronouce?

    @ericvsmith
    Copy link
    Member Author

    I agree. That's one of the reasons I un-assigned it to me.

    Well, that and I couldn't get it to pass all tests.

    @gvanrossum
    Copy link
    Member

    Not it.

    @gvanrossum gvanrossum removed their assignment Jan 6, 2009
    @rhettinger
    Copy link
    Contributor

    Am closing this one. It is pointless and counter-productive unless
    there is a firm decision that % formatting is definitely going away (and
    migration tools have been developed). Right now, it looks like there is
    some chance that it might pull through for a few versions.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants