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
91e3b9d8
Kaydet (Commit)
91e3b9d8
authored
May 28, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Deprecate contextlib.nested(). The with-statement now provides this functionality directly.
üst
fb12391c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
10 additions
and
123 deletions
+10
-123
contextlib.rst
Doc/library/contextlib.rst
+2
-0
3.1.rst
Doc/whatsnew/3.1.rst
+3
-0
contextlib.py
Lib/contextlib.py
+3
-0
test_contextlib.py
Lib/test/test_contextlib.py
+0
-122
NEWS
Misc/NEWS
+2
-1
No files found.
Doc/library/contextlib.rst
Dosyayı görüntüle @
91e3b9d8
...
@@ -80,6 +80,8 @@ Functions provided:
...
@@ -80,6 +80,8 @@ Functions provided:
:meth:`__exit__` methods should avoid raising exceptions, and in particular they
:meth:`__exit__` methods should avoid raising exceptions, and in particular they
should not re-raise a passed-in exception.
should not re-raise a passed-in exception.
.. deprecated:: 3.1
The with-statement now supports this functionality directly.
.. function:: closing(thing)
.. function:: closing(thing)
...
...
Doc/whatsnew/3.1.rst
Dosyayı görüntüle @
91e3b9d8
...
@@ -164,6 +164,9 @@ Some smaller changes made to the core Python language are:
...
@@ -164,6 +164,9 @@ Some smaller changes made to the core Python language are:
... if '<critical>' in line:
... if '<critical>' in line:
... outfile.write(line)
... outfile.write(line)
With the new syntax, the :func:`contextlib.nested` function is no longer
needed and is not deprecated.
(Contributed by Georg Brandl and Mattias Brändström;
(Contributed by Georg Brandl and Mattias Brändström;
`appspot issue 53094 <http://codereview.appspot.com/53094>`_.)
`appspot issue 53094 <http://codereview.appspot.com/53094>`_.)
...
...
Lib/contextlib.py
Dosyayı görüntüle @
91e3b9d8
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
sys
import
sys
from
functools
import
wraps
from
functools
import
wraps
from
warnings
import
warn
__all__
=
[
"contextmanager"
,
"nested"
,
"closing"
]
__all__
=
[
"contextmanager"
,
"nested"
,
"closing"
]
...
@@ -101,6 +102,8 @@ def nested(*managers):
...
@@ -101,6 +102,8 @@ def nested(*managers):
<body>
<body>
"""
"""
warn
(
"With-statements now directly support multiple context managers"
,
DeprecationWarning
,
2
)
exits
=
[]
exits
=
[]
vars
=
[]
vars
=
[]
exc
=
(
None
,
None
,
None
)
exc
=
(
None
,
None
,
None
)
...
...
Lib/test/test_contextlib.py
Dosyayı görüntüle @
91e3b9d8
...
@@ -100,128 +100,6 @@ class ContextManagerTestCase(unittest.TestCase):
...
@@ -100,128 +100,6 @@ class ContextManagerTestCase(unittest.TestCase):
self
.
assertEqual
(
baz
.
foo
,
'bar'
)
self
.
assertEqual
(
baz
.
foo
,
'bar'
)
self
.
assertEqual
(
baz
.
__doc__
,
"Whee!"
)
self
.
assertEqual
(
baz
.
__doc__
,
"Whee!"
)
class
NestedTestCase
(
unittest
.
TestCase
):
# XXX This needs more work
def
test_nested
(
self
):
@contextmanager
def
a
():
yield
1
@contextmanager
def
b
():
yield
2
@contextmanager
def
c
():
yield
3
with
nested
(
a
(),
b
(),
c
())
as
(
x
,
y
,
z
):
self
.
assertEqual
(
x
,
1
)
self
.
assertEqual
(
y
,
2
)
self
.
assertEqual
(
z
,
3
)
def
test_nested_cleanup
(
self
):
state
=
[]
@contextmanager
def
a
():
state
.
append
(
1
)
try
:
yield
2
finally
:
state
.
append
(
3
)
@contextmanager
def
b
():
state
.
append
(
4
)
try
:
yield
5
finally
:
state
.
append
(
6
)
try
:
with
nested
(
a
(),
b
())
as
(
x
,
y
):
state
.
append
(
x
)
state
.
append
(
y
)
1
/
0
except
ZeroDivisionError
:
self
.
assertEqual
(
state
,
[
1
,
4
,
2
,
5
,
6
,
3
])
else
:
self
.
fail
(
"Didn't raise ZeroDivisionError"
)
def
test_nested_right_exception
(
self
):
state
=
[]
@contextmanager
def
a
():
yield
1
class
b
(
object
):
def
__enter__
(
self
):
return
2
def
__exit__
(
self
,
*
exc_info
):
try
:
raise
Exception
()
except
:
pass
try
:
with
nested
(
a
(),
b
())
as
(
x
,
y
):
1
/
0
except
ZeroDivisionError
:
self
.
assertEqual
((
x
,
y
),
(
1
,
2
))
except
Exception
:
self
.
fail
(
"Reraised wrong exception"
)
else
:
self
.
fail
(
"Didn't raise ZeroDivisionError"
)
def
test_nested_b_swallows
(
self
):
@contextmanager
def
a
():
yield
@contextmanager
def
b
():
try
:
yield
except
:
# Swallow the exception
pass
try
:
with
nested
(
a
(),
b
()):
1
/
0
except
ZeroDivisionError
:
self
.
fail
(
"Didn't swallow ZeroDivisionError"
)
def
test_nested_break
(
self
):
@contextmanager
def
a
():
yield
state
=
0
while
True
:
state
+=
1
with
nested
(
a
(),
a
()):
break
state
+=
10
self
.
assertEqual
(
state
,
1
)
def
test_nested_continue
(
self
):
@contextmanager
def
a
():
yield
state
=
0
while
state
<
3
:
state
+=
1
with
nested
(
a
(),
a
()):
continue
state
+=
10
self
.
assertEqual
(
state
,
3
)
def
test_nested_return
(
self
):
@contextmanager
def
a
():
try
:
yield
except
:
pass
def
foo
():
with
nested
(
a
(),
a
()):
return
1
return
10
self
.
assertEqual
(
foo
(),
1
)
class
ClosingTestCase
(
unittest
.
TestCase
):
class
ClosingTestCase
(
unittest
.
TestCase
):
# XXX This needs more work
# XXX This needs more work
...
...
Misc/NEWS
Dosyayı görüntüle @
91e3b9d8
...
@@ -15,7 +15,8 @@ Core and Builtins
...
@@ -15,7 +15,8 @@ Core and Builtins
- Issue #6089: Fixed str.format with certain invalid field specifiers
- Issue #6089: Fixed str.format with certain invalid field specifiers
that would raise SystemError.
that would raise SystemError.
- Added support for multiple context managers in the same with statement.
- Added support for multiple context managers in the same with-statement.
Deprecated contextlib.nested() which is no longer needed.
- Issue #5829: complex("1e500") no longer raises OverflowError. This
- Issue #5829: complex("1e500") no longer raises OverflowError. This
makes it consistent with float("1e500") and interpretation of real
makes it consistent with float("1e500") and interpretation of real
...
...
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