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
c1c3292d
Kaydet (Commit)
c1c3292d
authored
Ara 06, 2016
tarafından
Ned Deily
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #28835: Tidy previous showwarning changes based on review comments.
Patch by Serhiy Storchaka.
üst
9a554959
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
20 deletions
+19
-20
warnings.py
Lib/warnings.py
+19
-20
No files found.
Lib/warnings.py
Dosyayı görüntüle @
c1c3292d
...
@@ -80,31 +80,39 @@ def _formatwarnmsg_impl(msg):
...
@@ -80,31 +80,39 @@ def _formatwarnmsg_impl(msg):
return
s
return
s
# Keep a reference to check if the function was replaced
# Keep a reference to check if the function was replaced
_showwarning
=
showwarning
_showwarning
_orig
=
showwarning
def
_showwarnmsg
(
msg
):
def
_showwarnmsg
(
msg
):
"""Hook to write a warning to a file; replace if you like."""
"""Hook to write a warning to a file; replace if you like."""
showwarning
=
globals
()
.
get
(
'showwarning'
,
_showwarning
)
try
:
if
showwarning
is
not
_showwarning
:
sw
=
showwarning
except
NameError
:
pass
else
:
if
sw
is
not
_showwarning_orig
:
# warnings.showwarning() was replaced
# warnings.showwarning() was replaced
if
not
callable
(
showwarning
):
if
not
callable
(
sw
):
raise
TypeError
(
"warnings.showwarning() must be set to a "
raise
TypeError
(
"warnings.showwarning() must be set to a "
"function or method"
)
"function or method"
)
showwarning
(
msg
.
message
,
msg
.
category
,
msg
.
filename
,
msg
.
lineno
,
sw
(
msg
.
message
,
msg
.
category
,
msg
.
filename
,
msg
.
lineno
,
msg
.
file
,
msg
.
line
)
msg
.
file
,
msg
.
line
)
return
return
_showwarnmsg_impl
(
msg
)
_showwarnmsg_impl
(
msg
)
# Keep a reference to check if the function was replaced
# Keep a reference to check if the function was replaced
_formatwarning
=
formatwarning
_formatwarning
_orig
=
formatwarning
def
_formatwarnmsg
(
msg
):
def
_formatwarnmsg
(
msg
):
"""Function to format a warning the standard way."""
"""Function to format a warning the standard way."""
formatwarning
=
globals
()
.
get
(
'formatwarning'
,
_formatwarning
)
try
:
if
formatwarning
is
not
_formatwarning
:
fw
=
formatwarning
except
NameError
:
pass
else
:
if
fw
is
not
_formatwarning_orig
:
# warnings.formatwarning() was replaced
# warnings.formatwarning() was replaced
return
formatwarning
(
msg
.
message
,
msg
.
category
,
return
fw
(
msg
.
message
,
msg
.
category
,
msg
.
filename
,
msg
.
lineno
,
line
=
msg
.
line
)
msg
.
filename
,
msg
.
lineno
,
line
=
msg
.
line
)
return
_formatwarnmsg_impl
(
msg
)
return
_formatwarnmsg_impl
(
msg
)
...
@@ -446,21 +454,13 @@ class catch_warnings(object):
...
@@ -446,21 +454,13 @@ class catch_warnings(object):
self
.
_module
.
filters
=
self
.
_filters
[:]
self
.
_module
.
filters
=
self
.
_filters
[:]
self
.
_module
.
_filters_mutated
()
self
.
_module
.
_filters_mutated
()
self
.
_showwarning
=
self
.
_module
.
showwarning
self
.
_showwarning
=
self
.
_module
.
showwarning
self
.
_showwarnmsg
=
self
.
_module
.
_showwarnmsg
self
.
_showwarnmsg_impl
=
self
.
_module
.
_showwarnmsg_impl
self
.
_showwarnmsg_impl
=
self
.
_module
.
_showwarnmsg_impl
if
self
.
_record
:
if
self
.
_record
:
log
=
[]
log
=
[]
self
.
_module
.
_showwarnmsg_impl
=
log
.
append
def
showarnmsg_logger
(
msg
):
nonlocal
log
log
.
append
(
msg
)
self
.
_module
.
_showwarnmsg_impl
=
showarnmsg_logger
# Reset showwarning() to the default implementation to make sure
# Reset showwarning() to the default implementation to make sure
# that _showwarnmsg() calls _showwarnmsg_impl()
# that _showwarnmsg() calls _showwarnmsg_impl()
self
.
_module
.
showwarning
=
self
.
_module
.
_showwarning
self
.
_module
.
showwarning
=
self
.
_module
.
_showwarning_orig
return
log
return
log
else
:
else
:
return
None
return
None
...
@@ -471,7 +471,6 @@ class catch_warnings(object):
...
@@ -471,7 +471,6 @@ class catch_warnings(object):
self
.
_module
.
filters
=
self
.
_filters
self
.
_module
.
filters
=
self
.
_filters
self
.
_module
.
_filters_mutated
()
self
.
_module
.
_filters_mutated
()
self
.
_module
.
showwarning
=
self
.
_showwarning
self
.
_module
.
showwarning
=
self
.
_showwarning
self
.
_module
.
_showwarnmsg
=
self
.
_showwarnmsg
self
.
_module
.
_showwarnmsg_impl
=
self
.
_showwarnmsg_impl
self
.
_module
.
_showwarnmsg_impl
=
self
.
_showwarnmsg_impl
...
...
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