Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
01928f6c
Kaydet (Commit)
01928f6c
authored
Ara 06, 2016
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge 3.6
üst
16e49bf4
8ef46be2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
2 deletions
+60
-2
__init__.py
Lib/test/test_warnings/__init__.py
+45
-0
warnings.py
Lib/warnings.py
+12
-2
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_warnings/__init__.py
Dosyayı görüntüle @
01928f6c
...
...
@@ -944,6 +944,51 @@ class CatchWarningTests(BaseTest):
self
.
assertTrue
(
wmod
.
filters
is
not
orig_filters
)
self
.
assertTrue
(
wmod
.
filters
is
orig_filters
)
def
test_record_override_showwarning_before
(
self
):
# Issue #28089: If warnings.showwarning() was overriden, make sure
# that catch_warnings(record=True) overrides it again.
text
=
"This is a warning"
wmod
=
self
.
module
my_log
=
[]
def
my_logger
(
message
,
category
,
filename
,
lineno
,
file
=
None
,
line
=
None
):
nonlocal
my_log
my_log
.
append
(
message
)
# Override warnings.showwarning() before calling catch_warnings()
with
support
.
swap_attr
(
wmod
,
'showwarning'
,
my_logger
):
with
wmod
.
catch_warnings
(
module
=
wmod
,
record
=
True
)
as
log
:
self
.
assertIsNot
(
wmod
.
showwarning
,
my_logger
)
wmod
.
simplefilter
(
"always"
)
wmod
.
warn
(
text
)
self
.
assertIs
(
wmod
.
showwarning
,
my_logger
)
self
.
assertEqual
(
len
(
log
),
1
,
log
)
self
.
assertEqual
(
log
[
0
]
.
message
.
args
[
0
],
text
)
self
.
assertEqual
(
my_log
,
[])
def
test_record_override_showwarning_inside
(
self
):
# Issue #28089: It is possible to override warnings.showwarning()
# in the catch_warnings(record=True) context manager.
text
=
"This is a warning"
wmod
=
self
.
module
my_log
=
[]
def
my_logger
(
message
,
category
,
filename
,
lineno
,
file
=
None
,
line
=
None
):
nonlocal
my_log
my_log
.
append
(
message
)
with
wmod
.
catch_warnings
(
module
=
wmod
,
record
=
True
)
as
log
:
wmod
.
simplefilter
(
"always"
)
wmod
.
showwarning
=
my_logger
wmod
.
warn
(
text
)
self
.
assertEqual
(
len
(
my_log
),
1
,
my_log
)
self
.
assertEqual
(
my_log
[
0
]
.
args
[
0
],
text
)
self
.
assertEqual
(
log
,
[])
def
test_check_warnings
(
self
):
# Explicit tests for the test.support convenience wrapper
wmod
=
self
.
module
...
...
Lib/warnings.py
Dosyayı görüntüle @
01928f6c
...
...
@@ -447,11 +447,20 @@ class catch_warnings(object):
self
.
_module
.
_filters_mutated
()
self
.
_showwarning
=
self
.
_module
.
showwarning
self
.
_showwarnmsg
=
self
.
_module
.
_showwarnmsg
self
.
_showwarnmsg_impl
=
self
.
_module
.
_showwarnmsg_impl
if
self
.
_record
:
log
=
[]
def
showarnmsg
(
msg
):
def
showarnmsg_logger
(
msg
):
nonlocal
log
log
.
append
(
msg
)
self
.
_module
.
_showwarnmsg
=
showarnmsg
self
.
_module
.
_showwarnmsg_impl
=
showarnmsg_logger
# Reset showwarning() to the default implementation to make sure
# that _showwarnmsg() calls _showwarnmsg_impl()
self
.
_module
.
showwarning
=
self
.
_module
.
_showwarning
return
log
else
:
return
None
...
...
@@ -463,6 +472,7 @@ class catch_warnings(object):
self
.
_module
.
_filters_mutated
()
self
.
_module
.
showwarning
=
self
.
_showwarning
self
.
_module
.
_showwarnmsg
=
self
.
_showwarnmsg
self
.
_module
.
_showwarnmsg_impl
=
self
.
_showwarnmsg_impl
# filters contains a sequence of filter 5-tuples
...
...
Misc/NEWS
Dosyayı görüntüle @
01928f6c
...
...
@@ -165,6 +165,9 @@ Core and Builtins
Library
-------
-
Issue
#
28089
:
Fix
a
regression
introduced
in
warnings
.
catch_warnings
():
call
warnings
.
showwarning
()
if
it
was
overriden
inside
the
context
manager
.
-
Issue
#
27172
:
To
assist
with
upgrades
from
2.7
,
the
previously
documented
deprecation
of
``
inspect
.
getfullargspec
()``
has
been
reversed
.
This
decision
may
be
revisited
again
after
the
Python
2.7
branch
is
no
longer
officially
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment