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

Check documentation examples for fatal errors #6475

Merged
merged 8 commits into from
Apr 30, 2022

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Apr 29, 2022

We missed the syntax error fixed in 98996bd because we were disabling fatal errors when checking "good.py" in the message examples.

I also noticed syntax-error is slightly different from astroid-error so added it to the messages added in #6365

@jacobtylerwalls jacobtylerwalls added the Maintenance Discussion or action around maintaining pylint or the dev workflow label Apr 29, 2022
@jacobtylerwalls jacobtylerwalls added this to the 2.14.0 milestone Apr 29, 2022
@coveralls
Copy link

coveralls commented Apr 29, 2022

Pull Request Test Coverage Report for Build 2250189067

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 95.146%

Files with Coverage Reduction New Missed Lines %
pylint/testutils/pyreverse.py 1 97.92%
Totals Coverage Status
Change from base Build 2246868922: 0.03%
Covered Lines: 15779
Relevant Lines: 16584

💛 - Coveralls

@jacobtylerwalls jacobtylerwalls merged commit 5f7fac5 into pylint-dev:main Apr 30, 2022
@jacobtylerwalls jacobtylerwalls deleted the doc-fatal-errors branch April 30, 2022 14:19
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.

I started a review but I wasn't fast enough 😄

Comment on lines +6 to +7
actual = "test_result"
self.assertEqual(actual, "expected")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
actual = "test_result"
self.assertEqual(actual, "expected")
# Nothing, as an assert of a string literal will always pass
pass

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess this is just taste and could go either way, but I was figuring the most likely mistake a beginner makes is not "oh I don't need to assert in the first place" but "oops I was trying to assert a comparison but I forgot to put the right hand side of it". So the solution is to put in the right hand side.

Copy link
Member

Choose a reason for hiding this comment

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

Make sense, Daniel also think this example was better so we kept it in the follow-up MR :)

Comment on lines 2 to 4
actual = "test"
wanted = "Directly asserting a string literal will always pass"
assert actual == wanted
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
actual = "test"
wanted = "Directly asserting a string literal will always pass"
assert actual == wanted
# Nothing, as an assert of a string literal will always pass
pass

@@ -91,7 +91,7 @@ def __init__(self, test_file: Tuple[str, Path]) -> None:
args_list=[
str(test_file[1]),
"--disable=all",
f"--enable={test_file[0]}",
f"--enable={test_file[0]},astroid-error,fatal,syntax-error",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
f"--enable={test_file[0]},astroid-error,fatal,syntax-error",
f"--enable={test_file[0]},F,E",

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I don't think we want to enable all errors, though. Just the fatal ones from pylint/astroid breaking, not antipatterns in the code under test.

Copy link
Member

Choose a reason for hiding this comment

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

What would be an example of error we want to keep when we're not specifically documenting it ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I thought I remembered the original discussion was "don't try to pass every pylint check" but you have a point that maybe errors are worth avoiding. Things like undefined-variable can be tedious to avoid if you have initialize all your thing and my_list etc. Let me see what fails if we add this.

Copy link
Member Author

Choose a reason for hiding this comment

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

some examples (there are more):

doc/data/messages/w/wrong-import-order/good.py:6:0: E0611: No name 'utils' in module '' (no-name-in-module)
doc/data/messages/y/yield-inside-async-function/good.py:6:0: E0102: function already defined line 1 (function-redefined)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm yeah wrong-import-order is possible to do if we remove the "our own lib" part but then it would be incomplete. For the other one we might need to find a way to propose multiple solution to the same bad.py but this is a non trivial refactor to do. I was thinking generally that being forced to create example without error would make the examples better but let's revisit that later when the cost to do it is lower.

Copy link
Member Author

Choose a reason for hiding this comment

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

The boundary is probably subjective. I asked a contributor to fix an easy TypeError from not passing an argument to a function in #6472

Copy link
Member

Choose a reason for hiding this comment

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

We could also explicitly disable the errors in the example ? (# pylint: disable=no-name-in-module for example) Would prevent us from not seeing that there's an issue in an example.

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