Why does PEP-343 use type() in this situation here?
mgr = (EXPR)
exit = type(mgr).__exit__ # Not calling it yet
value = type(mgr).__enter__(mgr)
Couldn’t we just as well use exit = mgr.__exit__ and value = mgr.__enter__()? Seems simpler to me, but I assume I’m missing something.
Of course the PEP could use attributes of the instance itself instead of attributes of the type, but this would be in contrast to the use of special methods in Python. For example
is translated to
and not to
as shown by the following example:
So, to be consistent with the rest of Python, the special methods
__enter__()and__exit__()should also be looked up in the type’s dictionary first.