New submission from Paul Wiseman:

I found this behaviour today and thought it was weird so asked the question on 
SO here 
http://stackoverflow.com/questions/12632894/why-doesnt-getattr-work-with-exit/12632972#12632972

basically if I attributes are returned dynamically, they seem to get overlooked 
by the code that runs the with statements.

>>> class FileHolder(object):
...    def __init__(self,*args,**kwargs):
...        self.f= file(*args,**kwargs)
...    def __getattr__(self,item):
...        return getattr(self.f,item)
...
>>> a= FileHolder("a","w")
>>> a.write
<built-in method write of file object at 0x018D75F8>
>>> with a as f:
...   print f
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: __exit__
>>> a.__exit__
<built-in method __exit__ of file object at 0x018D75F8>

----------
components: Library (Lib)
messages: 171399
nosy: Paul.Wiseman
priority: normal
severity: normal
status: open
title: with statement executes type(obj).__exit__ rather than 
getattr(obj,"__exit__")
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16068>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to