-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Refactor and typing of OutputLine #5060
Conversation
msg_id: str, | ||
line: Optional[int] = None, | ||
node: Optional[nodes.NodeNG] = None, | ||
args: Any = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to what we did for Message
in #5050. This should at some point be fully investigated and changed.
if isinstance(other, MessageTest): | ||
if self.confidence and other.confidence: | ||
return super().__eq__(other) | ||
return self[:-1] == other[:-1] | ||
return tuple(self[:-1]) == tuple(other[:-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy
complains that on this line the self
to __eq__
is no longer a MessageTest
. Making both sides a tuple solves this issue.
column: str | ||
object: Any | ||
column: int | ||
object: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have checked the full test suite by printing object in OutputLine.from_msg()
. This was always str
, which is to be expected since we are dealing with csv
and output lines
here.
def to_csv(self): | ||
return tuple(self) | ||
def to_csv(self) -> Tuple[str, str, str, str, str, str]: | ||
return tuple(str(i) for i in self) # type: ignore # pylint: disable=not-an-iterable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pylint
finds that self
is non-iterable, although I think we can assume it is, right?
Furthermore, mypy
sees the return value as being Tuple[str, ...]
. I added checks with a temp value and isinstance(temp_csv, Tuple) and len(temp_csv) == 6
, but it kept denying the correct size. Eventually I opted to add an ignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdce8p btw, this is a false positive right? Or am I missing some edge case where this is indeed a valid error?
assert csv == ( | ||
"missing-docstring", | ||
"line", | ||
"1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we are checking the to_csv()
method here, so line
and column
should be str
again.
pylint/testutils/output_line.py
Outdated
if isinstance(row, Iterable) and len(row) == 6: | ||
return cls(row[0], int(row[1]), column, row[3], row[4], row[5]) | ||
if isinstance(row, Iterable) and len(row) == 5: | ||
return cls(row[0], int(row[1]), column, row[3], row[4], HIGH.name) | ||
raise IndexError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could uniformize the expected text output by adding the confidence everywhere, so there's only one type of output and we can treat all expected message the same ? (This would prevent big diff where we add the confidence after upgrading the expected output). @cdce8p what do you think, I remember that we had this conversation already at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should definitely be part of a separate PR and would then ideally follow after this. If desired I can go and create this. Should be as easy as running python tests/test_functional.py --update-functional-output
and updating the typing and this function here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just my personal opinion: I don't see much value in adding HIGH
to almost every pylint error in all functional tests. Especially since it's the last value, it would be much more useful to only specify it if it's different (i.e. not HIGH
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree with the no added value argument, I think Pierre makes a valid point that when we do this once we will then have less larger diffs after people use the --update-functional-output
to update tests after they have added new cases. I saw this during my own work as well, where all test data gets updated because of it.
I don't think it would hurt to do this once and would allow simplifying the code here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can update / revert --update-functional-output
to only add different confidence values π Then we would only need to update a few.
Anyway, doesn't matter the decision, this should be part of another PR. (I saw a question about that earlier.)
Pull Request Test Coverage Report for Build 1263765687
π - Coveralls |
def __new__( | ||
cls, | ||
msg_id: str, | ||
line: Optional[int] = None, | ||
node: Optional[nodes.NodeNG] = None, | ||
args: Any = None, | ||
confidence: Optional[Confidence] = None, | ||
) -> "MessageTest": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we would use typing.NamedTuple
with default values instead. However that requires Python 3.6.1 -> see #5065
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to block this PR before consensus is reached there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think that would make sense here. Even if we reach a decision, the version bump would likely be in 2.12
at the earliest.
def __eq__(self, other: object) -> bool: | ||
if isinstance(other, MessageTest): | ||
if self.confidence and other.confidence: | ||
return super().__eq__(other) | ||
return self[:-1] == other[:-1] | ||
return tuple(self[:-1]) == tuple(other[:-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be an even better candidate for a dataclass
. That however requires Python 3.7 π
pylint/testutils/output_line.py
Outdated
if isinstance(row, Iterable) and len(row) == 6: | ||
return cls(row[0], int(row[1]), column, row[3], row[4], row[5]) | ||
if isinstance(row, Iterable) and len(row) == 5: | ||
return cls(row[0], int(row[1]), column, row[3], row[4], HIGH.name) | ||
raise IndexError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just my personal opinion: I don't see much value in adding HIGH
to almost every pylint error in all functional tests. Especially since it's the last value, it would be much more useful to only specify it if it's different (i.e. not HIGH
).
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
for more information, see https://pre-commit.ci
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last comment from me. I'll leave the rest to you @Pierre-Sassoulas
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π
Type of Changes
Description
This brings
OutputLine
in line with the classes dealing withMessage
by making theline
andcolumn
attributesint
. This has increased the size of the diff but I felt that makingline
andcolumn
int
throughout the codebase would eventually be worthwhile.OutputLine
incsv
form still only consists ofstr
(in fact we now make sure this is the case) but whenever we deal with it "internally" we can now assumeline
andcolumn
areint
.The tests have also been changed to accommodate for this.