Skip to content

warnings in interactive sessions #43816

Closed

Description

@malemburg
BPO 1539925
Nosy @malemburg, @birkenfeld, @ncoghlan, @vadmium, @serhiy-storchaka

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 = None
created_at = <Date 2006-08-14.11:03:41.000>
labels = ['3.7', 'type-feature', 'library']
title = 'warnings in interactive sessions'
updated_at = <Date 2017-11-14.01:01:29.867>
user = 'https://github.com/malemburg'

bugs.python.org fields:

activity = <Date 2017-11-14.01:01:29.867>
actor = 'ncoghlan'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2006-08-14.11:03:41.000>
creator = 'lemburg'
dependencies = []
files = []
hgrepos = []
issue_num = 1539925
keywords = []
message_count = 5.0
messages = ['60969', '85079', '199793', '306141', '306180']
nosy_count = 6.0
nosy_names = ['lemburg', 'georg.brandl', 'ncoghlan', 'martin.panter', 'serhiy.storchaka', 'Alan.Cristhian']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue1539925'
versions = ['Python 3.7']

Activity

  1. malemburg commented on Aug 14, 2006

    @malemburg
    MemberAuthor

    Carried over from Patch bpo-1538956 description:

    During testing I found that the warning registry
    defaults to only issueing warnings once per module and
    line number.

    I suppose this is enough for debugging code, but it
    feels weird when trying things in the interactive
    session, as you only get the warnings once in that
    context (and for the whole session), regardless of the
    fact that you're entering new lines of code all the time.

    The reason is that the warning framework registers
    warnings based on line number which usually is 1 in
    interactive sessions.

    In general, it might be a better idea to have a single
    global warning registry and then include the module
    name or id in the registry key. Currently, the warning
    framework creates a new registry per (module) context.

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Aug 14, 2006
  3. brettcannon commented on Apr 1, 2009

    @brettcannon
    Member

    Not a bad idea, although it would require some work to make it work in a
    backwards-compatible fashion.

  4. removed their assignment
    on Apr 1, 2009
  5. birkenfeld commented on Oct 13, 2013

    @birkenfeld
    Member

    Is there still any interest in this?

  6. serhiy-storchaka commented on Nov 13, 2017

    @serhiy-storchaka
    Member

    Looks reasonable to me. Perhaps we should port the solution from IPython:
    ipython/ipython#6611.

  7. ncoghlan commented on Nov 14, 2017

    @ncoghlan
    Contributor

    As a user, what would I actually gain from being warned more than once per session that a particular API I'm using is deprecated?

    If I want that behaviour, I can already opt in to it by doing "warnings.simplefilter('always')".

    As things stand, the perpetually reset line counter just means that the effective default at the REPL is "warnings.simplefilter('module:::main')"

  8. transferred this issue fromon Apr 10, 2022
  9. added
    3.12only security fixes
    and removed on Oct 5, 2022
  10. added
    3.13only security fixes
    and removed
    3.12only security fixes
    on May 14, 2023
  11. added
    pendingThe issue will be closed if no feedback is provided
    and removed
    3.13only security fixes
    on Sep 18, 2025
  12. iritkatriel commented on Sep 18, 2025

    @iritkatriel
    Member

    Marking as pending as this is almost 20 years old and it doesn't look like there's consensus for implementing it.

  13. ncoghlan commented on Sep 18, 2025

    @ncoghlan
    Contributor

    Checking Python 3.12 vs Python 3.13, it seems the new REPL actually implements this feature request:

    $ python3.12
    Python 3.12.11 (main, Jun 12 2025, 00:00:00) [GCC 15.1.1 20250521 (Red Hat 15.1.1-2)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import warnings
    >>> def f():
    ...     warnings.warn("Example", stacklevel=1)
    ...
    >>> f()
    <stdin>:2: UserWarning: Example
    >>> f()
    >>> f()
    >>> f()
    >>>
    
    $ python3.13
    Python 3.13.7 (main, Aug 14 2025, 00:00:00) [GCC 15.2.1 20250808 (Red Hat 15.2.1-1)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import warnings
    >>> def f():
    ...     warnings.warn("Example", stacklevel=1)
    ...
    >>> f()
    <python-input-1>:2: UserWarning: Example
    >>> f()
    <python-input-1>:2: UserWarning: Example
    >>> f()
    <python-input-1>:2: UserWarning: Example
    >>> f()
    <python-input-1>:2: UserWarning: Example
    >>>
    

    So I'll close this as completed in 3.13, rather than as not planned.

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

    3.13only security fixespendingThe issue will be closed if no feedback is providedstdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions