Bug report
Bug description:
With warnings.simplefilter("module") and warnings.warn(), I ran main.py which runs file1.py(module) and file2.py(module) as shown below:
*Memos:
- The doc says
"module" print the first occurrence of matching warnings for each module where the warning is issued (regardless of line number).
- I also used warnings.filterwarnings("module").
- I ran it on Windows and Linux.
my_project
|-main.py
|-file1.py(module)
└-file2.py(module)
main.py:
import warnings
warnings.simplefilter("module")
import file1, file2
file1.py:
import warnings
warnings.warn("Warning 1")
warnings.warn("Warning 2")
warnings.warn("Warning 3")
file2.py:
import warnings
warnings.warn("Warning 1")
warnings.warn("Warning 2")
warnings.warn("Warning 3")
Then, "module" print the first occurrence of matching warnings for each module where the warning is issued (regardless of line number)` as shown below:
...\my_project\file1.py:3: UserWarning: Warning 1
warnings.warn("Warning 1")
...\my_project\file1.py:4: UserWarning: Warning 2
warnings.warn("Warning 2")
...\my_project\file1.py:6: UserWarning: Warning 3
warnings.warn("Warning 3")
...\my_project\file2.py:3: UserWarning: Warning 1
warnings.warn("Warning 1")
...\my_project\file2.py:4: UserWarning: Warning 2
warnings.warn("Warning 2")
...\my_project\file2.py:6: UserWarning: Warning 3
warnings.warn("Warning 3")
Now with warnings.simplefilter("once") and warnings.warn(), I ran main.py which runs file1.py(module) and file2.py(module) as shown below:
*Memos:
- The doc says
"once" print only the first occurrence of matching warnings, regardless of location.
- I also used
warnings.filterwarnings("once").
- I ran it on Windows and Linux.
import warnings
warnings.simplefilter("once")
import file1, file2
But "once" print all occurrences of matching warnings, regardless of location as shown below:
...\my_project\file1.py:3: UserWarning: Warning 1
warnings.warn("Warning 1")
...\my_project\file1.py:4: UserWarning: Warning 2
warnings.warn("Warning 2")
...\my_project\file1.py:6: UserWarning: Warning 3
warnings.warn("Warning 3")
...\my_project\file2.py:3: UserWarning: Warning 1
warnings.warn("Warning 1")
...\my_project\file2.py:4: UserWarning: Warning 2
warnings.warn("Warning 2")
...\my_project\file2.py:6: UserWarning: Warning 3
warnings.warn("Warning 3")
CPython versions tested on:
3.11
Operating systems tested on:
Linux, Windows
Linked PRs
Bug report
Bug description:
With warnings.simplefilter("module") and warnings.warn(), I ran
main.pywhich runsfile1.py(module) andfile2.py(module) as shown below:*Memos:
"module" print the first occurrence of matching warnings for each module where the warning is issued (regardless of line number).main.py:file1.py:file2.py:Then,
"module"print the first occurrence of matching warnings for each module where the warning is issued (regardless of line number)` as shown below:Now with
warnings.simplefilter("once")andwarnings.warn(), I ranmain.pywhich runsfile1.py(module) andfile2.py(module) as shown below:*Memos:
"once" print only the first occurrence of matching warnings, regardless of location.warnings.filterwarnings("once").But "once" print all occurrences of matching warnings, regardless of location as shown below:
CPython versions tested on:
3.11
Operating systems tested on:
Linux, Windows
Linked PRs