Add typing to references of stream
and stream()
#4983
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of Changes
Description
The next instalment of breaking up #4954 into more manageable PR's.
This PR is based on two related commits which I felt should be part of the same PR as they deal with a similar topic.
The first is annotation of all implementations of
process_module
. This is fairly straightforward and covers addingnodes.Module
to the typing of the parameter and changingmodule
,astroid
and other parameter names to the new standard ofnode
. Asprocess_module
callsnode.stream()
often this seemed like a good first step to this PR.The second commit covers annotation of (most) functions with a reference to
stream
,filestream
or a similar parameter. There are two important comments about this commit.The first is for
pylint/checkers/similar.py
where I choose to useSTREAM_TYPES = Union[TextIO, BufferedReader, BytesIO]
. I did this because there seems to be a certain particularity withTextIO
andIOBase
. See the (small) discussion here: python/typeshed#3225 In practice this means that return types ofopen("b")
andopen("t")
are incompatible. This became problematic and is why I opted to introduceSTREAM_TYPES
. This also means that typing is a little more restrictive than usingIOBase
although in practice this probably won't make a real difference.The second is that in
pylint/utils/utils.py
I don't fully type theoptions
parameter and useTuple
. This is because trying to determine the type of the second argument of thistuple
became difficult and I didn't want to overstretch this PR. If we turn on some of the more stricter flags of mypy in the future this will probably show up again and should be solved then.