-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
non-writeable property 'name' in StringIO #598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
File objects don't have a writable A somewhat correct fix would be to 'undefine' My suggestion is to use |
I say let's make it a writable attribute of type str (or Text), that's the
closest you get to reality.
…--Guido (mobile)
|
For now I'm using this workaround in zulip's code: from six.moves import StringIO as _StringIO
class StringIO(_StringIO):
name = '' |
Can you just submit a PR that updates typeshed?
|
Add an attribute 'name' of type str to StringIO.StringIO in python2 and io.StringIO in python2 and python3. Fixes python#598.
Add an attribute 'name' of type str to StringIO.StringIO in python2 and io.StringIO in python2 and python3. Fixes #598.
I have a similar issuee. What I'm trying to do is treat a cx_Oracle.CLOB value like a stream (which seems quite natural, only the LOB API is a bit different). My attempt is like this:
Note: Actually I only need the read method in my code. The constructor fails with the exception Having non-writable attributes seems somewhat un-pythonic to me. |
StringIO
(I'm talking aboutio.StringIO
in python3 and python2 andStringIO.stringIO
in python2) doesn't have an attribute calledname
.However, we can set that attribute and assign it any value
But according to typeshed,
StringIO.StringIO
is a subclass ofIO[str]
andio.StringIO
is a subclass ofIO[Text]
. In typeshed,IO
definesname
using@property
. So there's a getter for it but no setter. So according to typeshed,StringIO.name
is readable (which is false until it is set it), but not writeable. This doesn't correspond to what happens at run-time.Maybe we can write a setter for it in
StringIO
. I don't know whether mypy currently supports setters.In some of zulip's tests, we're passing
StringIO
objects to functions which accept file-like objects. Since those functions (which are probably part of django) readname
of the file-like objects, we have to set a suitable value ofname
for those file-like objects. But when we do that, mypy complains:The text was updated successfully, but these errors were encountered: