Avoid overwriting a variable with value of different type. #1505
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.
Description
Avoids the following
mypy
error:Part of #1496.
The error was happening because the
data
variable was initially of typeInferenceData
but was later overwritten with a value of different type on the line:In general, assigning a value of a completely different type to an existing variable will cause both
mypy
andpylint
to complain about the assignment itself. In this case, theget_coords()
function itself was not type-hinted, i.e. its return type was considered to beAny
. This ledmypy
to incorrectly deduce that the return type must have preserved the existing type ofdata
, because not doing so would have been an immediate error.Renaming the assignment on that line to a new variable name avoids the current error as well as the possible future
mypy
orpylint
errors arising when and ifget_coords()
gets a type hint for its return type.Checklist