#11248: look up special methods on type.

This commit is contained in:
Georg Brandl 2011-03-20 21:51:37 +00:00
parent 310d1250c4
commit 8a1e5adb10
1 changed files with 4 additions and 4 deletions

View File

@ -238,8 +238,8 @@ Specification: The 'with' Statement
The translation of the above statement is: The translation of the above statement is:
mgr = (EXPR) mgr = (EXPR)
exit = mgr.__exit__ # Not calling it yet exit = type(mgr).__exit__ # Not calling it yet
value = mgr.__enter__() value = type(mgr).__enter__(mgr)
exc = True exc = True
try: try:
try: try:
@ -248,13 +248,13 @@ Specification: The 'with' Statement
except: except:
# The exceptional case is handled here # The exceptional case is handled here
exc = False exc = False
if not exit(*sys.exc_info()): if not exit(mgr, *sys.exc_info()):
raise raise
# The exception is swallowed if exit() returns true # The exception is swallowed if exit() returns true
finally: finally:
# The normal and non-local-goto cases are handled here # The normal and non-local-goto cases are handled here
if exc: if exc:
exit(None, None, None) exit(mgr, None, None, None)
Here, the lowercase variables (mgr, exit, value, exc) are internal Here, the lowercase variables (mgr, exit, value, exc) are internal
variables and not accessible to the user; they will most likely be variables and not accessible to the user; they will most likely be