Xiang Zhang added the comment:
Actually the docs says "This attribute is available when using the buffered I/O
classes from the io module", which means it's not always available since it
depends on an inner field set or not.
It's just like Python code:
>>> class CW:
... def __get__(self, obj, objtype):
... if obj._written:
... return obj._written
... else:
... raise AttributeError("characters_written")
... def __set__(self, obj, val):
... obj._written = val
...
>>> class MyOSError:
... characters_written = CW()
... def __init__(self):
... self._written = False
...
>>> dir(MyOSError())
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__',
'__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__',
'__str__', '__subclasshook__', '__weakref__', '_written', 'characters_written']
>>> MyOSError().characters_written
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in __get__
AttributeError: characters_written
----------
nosy: +xiang.zhang
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue30554>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com