Skip to content

-W command line options should have higher priority than PYTHONWARNINGS environmental variable #64554

Closed

Description

@Arfrever
mannequin
BPO 20355
Nosy @warsaw, @brettcannon, @pitrou, @larryhastings, @pjenvey, @ezio-melotti, @merwok, @briancurtin, @serhiy-storchaka
Dependencies
  • bpo-20373: Use test.script_helper.assert_python_ok() instead of subprocess.* in test.test_warnings
  • Files
  • python-warnings.patch
  • 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 2014-04-28.22:58:46.484>
    created_at = <Date 2014-01-22.21:41:46.788>
    labels = ['interpreter-core', 'type-feature']
    title = '-W command line options should have higher priority than PYTHONWARNINGS environmental variable'
    updated_at = <Date 2014-04-28.22:58:46.482>
    user = 'https://bugs.python.org/Arfrever'

    bugs.python.org fields:

    activity = <Date 2014-04-28.22:58:46.482>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-04-28.22:58:46.484>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2014-01-22.21:41:46.788>
    creator = 'Arfrever'
    dependencies = ['20373']
    files = ['33673']
    hgrepos = []
    issue_num = 20355
    keywords = ['patch']
    message_count = 13.0
    messages = ['208854', '208856', '208886', '209018', '209022', '209026', '209028', '209031', '209089', '209090', '212094', '217437', '217438']
    nosy_count = 11.0
    nosy_names = ['barry', 'brett.cannon', 'pitrou', 'larry', 'pjenvey', 'ezio.melotti', 'eric.araujo', 'Arfrever', 'brian.curtin', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue20355'
    versions = ['Python 3.5']

    Activity

    1. Arfrever commented on Jan 22, 2014

      Arfrevermannequin
      MannequinAuthor

      Currently Python has non-intuitive behavior such that PYTHONWARNINGS environmental variable has higher priority than -W command line options.

      $ python3.4 -c '__import__("warnings").warn("xxx", DeprecationWarning)'
      $ python3.4 -Wd -c '__import__("warnings").warn("xxx", DeprecationWarning)'
      -c:1: DeprecationWarning: xxx
      $ python3.4 -We -c '__import__("warnings").warn("xxx", DeprecationWarning)'
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
      DeprecationWarning: xxx
      $ PYTHONWARNINGS="e" python3.4 -Wd -c '__import__("warnings").warn("xxx", DeprecationWarning)'
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
      DeprecationWarning: xxx
      $ PYTHONWARNINGS="d" python3.4 -We -c '__import__("warnings").warn("xxx", DeprecationWarning)'
      -c:1: DeprecationWarning: xxx
      $

      I think that settings from -W command line options should have higher priority than PYTHONWARNINGS environmental variable.

      (Adding people from issue bpo-7301 to nosy list.)

    2. added
      type-bugAn unexpected behavior, bug, or error
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      on Jan 22, 2014
    3. pitrou commented on Jan 22, 2014

      @pitrou
      Member

      Agreed.

    4. added
      type-featureA feature request or enhancement
      and removed
      type-bugAn unexpected behavior, bug, or error
      on Jan 22, 2014
    5. Arfrever commented on Jan 23, 2014

      Arfrevermannequin
      MannequinAuthor

      The attached patch moves calls to PySys_AddWarnOption* for -W options to after parsing PYTHONWARNINGS.

      I think that this bug fix could be applied in Python 3.4. The patch does not introduce any failures in full test suite.

    6. pitrou commented on Jan 23, 2014

      @pitrou
      Member

      Well, 3.4 isn't supposed to receive behaviour changes anymore, unless Larry says it's ok.

    7. pitrou commented on Jan 23, 2014

      @pitrou
      Member

      About the patch (note the code review tool hasn't accepted it, so I'm commenting here):

      • in the tests, I think comparing stderr as-is will fail under Windows, where the line separator is b"\r\n"; better call splitlines() first
      • in the tests, I think it would be better to use test.script_helper.assert_python_ok() (it will automate some stuff for you), even though other tests don't in that file
      • in main.c, you need to Py_DECREF warning_options when you are done with it.
    8. larryhastings commented on Jan 24, 2014

      @larryhastings
      Contributor

      Is this behavior causing problems? How bad is it?

      Can I get more opinions about this than just Arfrever and Antoine? Not that I don't trust their opinions, I just want to see a larger sample size.

    9. pitrou commented on Jan 24, 2014

      @pitrou
      Member

      Is this behavior causing problems? How bad is it?

      Not really. It's just a bit suboptimal and counter-intuitive
      (local settings should trump global settings).

    10. Arfrever commented on Jan 24, 2014

      Arfrevermannequin
      MannequinAuthor

      The new patch includes changes suggested by Antoine. (This patch should be applied after patch from issue bpo-20373.)

    11. brettcannon commented on Jan 24, 2014

      @brettcannon
      Member

      I agree with Antoine; this can wait for Python 3.5.

    12. larryhastings commented on Jan 24, 2014

      @larryhastings
      Contributor

      Okay, then yes, let's save this for 3.5. Thanks!

    13. serhiy-storchaka commented on Feb 24, 2014

      @serhiy-storchaka
      Member

      Final patch should remove a workaround in Tools/scripts/run_tests.py.

    14. python-dev commented on Apr 28, 2014

      python-devmannequin
      Mannequin

      New changeset 78c0d80a04f9 by Antoine Pitrou in branch 'default':
      Issue bpo-20355: -W command line options now have higher priority than the PYTHONWARNINGS environment variable. Patch by Arfrever.
      http://hg.python.org/cpython/rev/78c0d80a04f9

      New changeset 925c0b611c02 by Antoine Pitrou in branch 'default':
      Remove a workaround for fixed issue bpo-20355.
      http://hg.python.org/cpython/rev/925c0b611c02

    15. pitrou commented on Apr 28, 2014

      @pitrou
      Member

      Committed. Thanks, Arfrever!

    16. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions