You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Activity
malemburg commentedon Aug 14, 2006
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.
brettcannon commentedon Apr 1, 2009
Not a bad idea, although it would require some work to make it work in a
backwards-compatible fashion.
birkenfeld commentedon Oct 13, 2013
Is there still any interest in this?
serhiy-storchaka commentedon Nov 13, 2017
Looks reasonable to me. Perhaps we should port the solution from IPython:
ipython/ipython#6611.
ncoghlan commentedon Nov 14, 2017
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')"
iritkatriel commentedon Sep 18, 2025
Marking as pending as this is almost 20 years old and it doesn't look like there's consensus for implementing it.
ncoghlan commentedon Sep 18, 2025
Checking Python 3.12 vs Python 3.13, it seems the new REPL actually implements this feature request:
So I'll close this as completed in 3.13, rather than as not planned.