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

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

Closed
Arfrever mannequin opened this issue Jan 22, 2014 · 13 comments
Closed
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@Arfrever
Copy link
Mannequin

Arfrever mannequin commented Jan 22, 2014

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']

    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Jan 22, 2014

    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.)

    @Arfrever Arfrever mannequin added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Jan 22, 2014
    @pitrou
    Copy link
    Member

    pitrou commented Jan 22, 2014

    Agreed.

    @pitrou pitrou added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Jan 22, 2014
    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Jan 23, 2014

    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.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 23, 2014

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

    @pitrou
    Copy link
    Member

    pitrou commented Jan 23, 2014

    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.

    @larryhastings
    Copy link
    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.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 24, 2014

    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).

    @Arfrever
    Copy link
    Mannequin Author

    Arfrever mannequin commented Jan 24, 2014

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

    @brettcannon
    Copy link
    Member

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

    @larryhastings
    Copy link
    Contributor

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

    @serhiy-storchaka
    Copy link
    Member

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

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 28, 2014

    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

    @pitrou
    Copy link
    Member

    pitrou commented Apr 28, 2014

    Committed. Thanks, Arfrever!

    @pitrou pitrou closed this as completed Apr 28, 2014
    @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) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants