Skip to content
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

Merged
merged 7 commits into from
Sep 23, 2021

Conversation

DanielNoord
Copy link
Collaborator

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Write a good description on what the PR does.

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

Description

This brings OutputLine in line with the classes dealing with Message by making the line and column attributes int. This has increased the size of the diff but I felt that making line and column int throughout the codebase would eventually be worthwhile. OutputLine in csv form still only consists of str (in fact we now make sure this is the case) but whenever we deal with it "internally" we can now assume line and column are int.
The tests have also been changed to accommodate for this.

@DanielNoord DanielNoord added the Maintenance Discussion or action around maintaining pylint or the dev workflow label Sep 21, 2021
msg_id: str,
line: Optional[int] = None,
node: Optional[nodes.NodeNG] = None,
args: Any = None,
Copy link
Collaborator Author

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])
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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.

pylint/testutils/output_line.py Outdated Show resolved Hide resolved
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
Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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",
Copy link
Collaborator Author

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.

Comment on lines 108 to 112
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
Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Member

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).

Copy link
Collaborator Author

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.

Copy link
Member

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.)

@coveralls
Copy link

coveralls commented Sep 22, 2021

Pull Request Test Coverage Report for Build 1263765687

  • 26 of 26 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 93.089%

Totals Coverage Status
Change from base Build 1257471391: 0.003%
Covered Lines: 13348
Relevant Lines: 14339

πŸ’› - Coveralls

Comment on lines +22 to +29
def __new__(
cls,
msg_id: str,
line: Optional[int] = None,
node: Optional[nodes.NodeNG] = None,
args: Any = None,
confidence: Optional[Confidence] = None,
) -> "MessageTest":
Copy link
Member

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

Copy link
Collaborator Author

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?

Copy link
Member

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.

Comment on lines +32 to +36
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])
Copy link
Member

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 Show resolved Hide resolved
pylint/testutils/output_line.py Outdated Show resolved Hide resolved
pylint/testutils/output_line.py Outdated Show resolved Hide resolved
pylint/testutils/output_line.py Outdated Show resolved Hide resolved
Comment on lines 108 to 112
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
Copy link
Member

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).

pylint/testutils/output_line.py Outdated Show resolved Hide resolved
pylint/testutils/output_line.py Outdated Show resolved Hide resolved
DanielNoord and others added 3 commits September 23, 2021 00:15
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Copy link
Member

@cdce8p cdce8p left a 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

pylint/testutils/output_line.py Outdated Show resolved Hide resolved
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘

@DanielNoord DanielNoord merged commit 5124f54 into pylint-dev:main Sep 23, 2021
@DanielNoord DanielNoord deleted the typing-outputline branch September 23, 2021 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Discussion or action around maintaining pylint or the dev workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants