This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document __warningregistry__
Type: behavior Stage:
Components: Library (Lib) Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka, steven.daprano
Priority: normal Keywords:

Created on 2018-10-10 01:50 by steven.daprano, last changed 2022-04-11 14:59 by admin.

Messages (4)
msg327449 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-10-10 01:50
The warnings module makes use of a per-module global ``__warningregister__`` which is briefly mentioned in the docs but not documented.

https://docs.python.org/3/library/warnings.html#warnings.warn_explicit

Given that it is part of the warn_explicit API, we should accept that the registry file is now part of the public API not just an implementation detail, and so we should explicitly document its existence and state the expected format.
msg327454 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-10 05:11
I don't think that it is necessary to state its format. It is an opaque dictionary, and its format is an implementation detail.
msg327463 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-10-10 09:15
On Wed, Oct 10, 2018 at 05:11:01AM +0000, Serhiy Storchaka wrote:
> I don't think that it is necessary to state its format. It is an 
> opaque dictionary, and its format is an implementation detail.

There is at least one use-case for wanting to manipulate the registry:

https://redd.it/9mqb45
msg327474 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-10 13:39
And this case looks like playing with implementation details.

The official way to make the specified warning emitted more than once is to use warnings.filterwarnings():

>>> import warnings
>>> warnings.filterwarnings('always', "NOBODY expects the Spanish Inquisition!", UserWarning)
>>> warnings.warn("NOBODY expects the Spanish Inquisition!")
<stdin>:1: UserWarning: NOBODY expects the Spanish Inquisition!
>>> warnings.warn("NOBODY expects the Spanish Inquisition!")
<stdin>:1: UserWarning: NOBODY expects the Spanish Inquisition!
History
Date User Action Args
2022-04-11 14:59:07adminsetgithub: 79129
2018-10-12 16:23:11eric.araujosettitle: Document __warningregister__ -> Document __warningregistry__
2018-10-10 13:39:39serhiy.storchakasetmessages: + msg327474
2018-10-10 09:15:45steven.dapranosetmessages: + msg327463
2018-10-10 05:11:01serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg327454
2018-10-10 01:50:43steven.dapranocreate