[Python-Dev] PEP 343 rewrite complete
Delaney, Timothy C (Timothy)
tdelaney at avaya.com
Thu Jun 2 22:45:19 CEST 2005
Phillip J. Eby wrote:
> That's not a bug, it's a feature. If the object doesn't have a
> 'close()'
> method, clearly it doesn't need to be closed. If it's the "wrong"
> object
> for what you're using it for in the body of the 'with' block, it'll
> show up
> there, so this doesn't hide any errors.
For those semantics, I think one of the following would be better:
with local(obj):
with scoped(obj):
but those semantics apply better to __enter__ and __exit__ anyway.
I think a "closing adaptor" should only work with objects that have a
close() method.
Perhaps:
with scoped_closable(obj):
Tim Delaney
More information about the Python-Dev
mailing list