Skip to content

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Aug 29, 2025

To review I'd suggest to use Hide whitespace.

@cdce8p cdce8p added Maintenance Discussion or action around maintaining pylint or the dev workflow Skip news 🔇 This change does not require a changelog entry labels Aug 29, 2025
Copy link

codecov bot commented Aug 29, 2025

Codecov Report

❌ Patch coverage is 98.43137% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.86%. Comparing base (e737d0c) to head (8ee42d1).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
pylint/checkers/base/basic_checker.py 96.07% 2 Missing ⚠️
pylint/checkers/classes/class_checker.py 95.65% 1 Missing ⚠️
pylint/checkers/classes/special_methods_checker.py 92.85% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (98.43%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10529      +/-   ##
==========================================
+ Coverage   95.84%   95.86%   +0.02%     
==========================================
  Files         177      177              
  Lines       19284    19308      +24     
==========================================
+ Hits        18483    18510      +27     
+ Misses        801      798       -3     
Files with missing lines Coverage Δ
pylint/checkers/base/basic_error_checker.py 95.41% <100.00%> (ø)
pylint/checkers/base/docstring_checker.py 97.70% <100.00%> (+0.05%) ⬆️
pylint/checkers/base/name_checker/checker.py 98.69% <100.00%> (+0.01%) ⬆️
...heckers/refactoring/implicit_booleaness_checker.py 100.00% <100.00%> (ø)
pylint/checkers/refactoring/refactoring_checker.py 98.18% <100.00%> (+0.12%) ⬆️
pylint/checkers/classes/class_checker.py 93.85% <95.65%> (+0.12%) ⬆️
pylint/checkers/classes/special_methods_checker.py 96.04% <92.85%> (+0.59%) ⬆️
pylint/checkers/base/basic_checker.py 98.08% <96.07%> (+<0.01%) ⬆️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This comment has been minimized.

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.

Yeah, this looks amazing.

Comment on lines -231 to -233
# Check *a, *b = ...
assign_target = node.targets[0]
# Check *a = b
Copy link
Member

Choose a reason for hiding this comment

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

Those comments were stangely placed, good job fixing them.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's one of the things I noticed with the match statement. It forces you to think about conditions in a more linear way compared to if statements which often improves the code itself.

if isinstance(decorator, nodes.Attribute):
if self._check_functools_or_not(decorator):
match decorator:
case nodes.Attribute(attrname="getter" | "setter" | "deleter"):
Copy link
Member

Choose a reason for hiding this comment

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

So elegant !

Comment on lines -312 to +319
elif isinstance(node, nodes.ClassDef):
metaclass = node.metaclass()
if metaclass and isinstance(metaclass, nodes.ClassDef):
case bases.Instance():
try:
metaclass.local_attr(NEXT_METHOD)
node.local_attr(NEXT_METHOD)
return True
except astroid.NotFoundError:
pass
case nodes.ClassDef():
metaclass = node.metaclass()
if metaclass and isinstance(metaclass, nodes.ClassDef):
try:
metaclass.local_attr(NEXT_METHOD)
return True
except astroid.NotFoundError:
pass
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this one is better as we had to duplicate some code. Maybe. (+0)

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 diff itself looks worse than it really is. The partial duplication is there already. I just replaced the if statements with case ... and indented the individual blocks.

return any(
self._is_node_return_ended(_child) for _child in all_but_handler
) and all(self._is_node_return_ended(_child) for _child in handlers)
case nodes.Assert(test=nodes.Const(value=value)) if not value:
Copy link
Member

Choose a reason for hiding this comment

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

Nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could even simplify this a bit further since we only really care about assert False. This should work

-case nodes.Assert(test=nodes.Const(value=value)):
+case nodes.Assert(test=nodes.Const(value=False)):
     ...

Will do that in a followup as it's technically a (minor) behavior change and not just refactoring.

This comment has been minimized.

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.

We might want to add the missing coverage to be safe.

@cdce8p
Copy link
Member Author

cdce8p commented Aug 30, 2025

We might want to add the missing coverage to be safe.

Thanks actually just a result of how coverage evaluates the ast. For else: return only the return line is marked as uncovered, whereas for case _: return both lines are. So the code coverage didn't really change.

Screenshot 2025-08-30 at 20 48 51

@Pierre-Sassoulas
Copy link
Member

I know that the code was not covered by automated test before the refactor, but the old code was tested by time since release and billions of use on very diverse codebases. The refactor with the new match statement isn't, so I don't think we can trust it as much as the old code without adding automated tests.

We might realize that the default match case is impossible to reach and remove it or pragma no-cover it because it's very hard to automatically test but still need to be there.

@cdce8p
Copy link
Member Author

cdce8p commented Aug 30, 2025

The refactor with the new match statement isn't, so I don't think we can trust it as much as the old code without adding automated tests.

Might be my own bias speaking here. After converting a lot of if statements, I think the transformations in this PR are quite safe. I've actually excluded the unsafe / questionable ones for latter.

We might realize that the default match case is impossible to reach and remove it or pragma no-cover it because it's very hard to automatically test but still need to be there.

After looking at the code again, the uncovered else case shouldn't ever be reached as we exclude all nodes which parent isn't DictComp, ListComp or SetComp earlier. Will go ahead and remove it. Will add a pragma: no cover for it.

This comment has been minimized.

@Pierre-Sassoulas
Copy link
Member

The refactor with the new match statement isn't, so I don't think we can trust it as much as the old code without adding automated tests.

Might be my own bias speaking here. After converting a lot of if statements, I think the transformations in this PR are quite safe. I've actually excluded the unsafe / questionable ones for latter.

Yeah, you know match better than me and it's probably safe, but (in my youth... 😛) I've been absolutely certain that a refactor was safe and didn't need new tests and then destroyed the productions of less impactful projects :)

@cdce8p
Copy link
Member Author

cdce8p commented Aug 30, 2025

I've been absolutely certain that a refactor was safe and didn't need new tests and then destroyed the productions of less impactful projects :)

True, happened to all of us at some point 😅

The primer runs do help to feel better about it though. Yes, it could be that there are one or two regressions hiding in the match PRs. However those could easily be fixed later, similar to the *_ I added earlier.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 8ee42d1

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 Skip news 🔇 This change does not require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants