-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
About pprint's stream arg #177
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
I think it's reasonable to switch this to Eventually we should introduce protocols and then we might be able to deal with this better. |
python/typing#11 sounds almost exactly like what I imagined for this. Alright, let's wait for Protocol support before thinking about a SupportsWrite protocol. I'll submit a pr for |
So, I did some testing and found out that the Python 2 implementation of pprint uses literal strings, i.e. In Py3, Note that the 2.7 stub currently has |
You seem to be making up terminology ("literal" strings usually refers to writing a string literal in source code, not to the type itself). But I understand your point. In Python 2 |
The usage of the term "literal string" was intended, example: https://github.com/python/cpython/blob/02f91871c1a976530cd2c566cbd6c85ad37f97a4/Lib/pprint.py#L140. Either way, |
According to the docs:
Currently the stream arg is specified as
TextIO
, which seems overly restrictive to me. I had my variable declared asIO[str]
, which supports the.write()
method just fine and would completely suffice, so I believe thatstream
should at least be stripped down toIO[str]
.However, since the code actually ony uses
stream.write()
(I checked the source to verify),IO[str]
still seems overly restrictive with its ~20 methods.Should a new private typing type be created in the stub that only defines
write()
?Related: #163
The text was updated successfully, but these errors were encountered: