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

[cfg] Upgrade to pylint 3.2.4 #4279

Merged
merged 1 commit into from
Jul 8, 2024
Merged

Conversation

bruntib
Copy link
Contributor

@bruntib bruntib commented Jun 27, 2024

No description provided.

@bruntib bruntib added dev env ⛑️ Development environment config ⚙️ dependencies 📦 Pull requests that update a dependency file labels Jun 27, 2024
@bruntib bruntib added this to the release 6.24.1 milestone Jun 27, 2024
@bruntib bruntib requested a review from cservakt June 27, 2024 15:52
@bruntib bruntib requested a review from vodorok as a code owner June 27, 2024 15:52
@bruntib bruntib force-pushed the pylint_upgrade branch 4 times, most recently from fccd454 to 9525937 Compare July 1, 2024 11:20
.pylintrc Outdated Show resolved Hide resolved
# Regular expression matching correct method names
method-rgx=[a-z_][a-z0-9_]{2,30}$
# Maximum number of characters on a single line.
max-line-length=100
Copy link
Collaborator

Choose a reason for hiding this comment

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

Previously, the maximum number of characters in a line was 80. Is it an automatically generated new value of max-line-length? Shouldn't have we sticked to previous number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks! pycodestyle is also checking this. By the way, pylint looks quite extensive in format checking. Would it be worth getting rid of pycodestyle? Would we lose anything with it? We could compare these two tools sometime in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I think it is redundant. We should check these parameters by one tool.

# Naming hint for method names
method-name-hint=[a-z_][a-z0-9_]{2,30}$
# Maximum number of lines in a module.
max-module-lines=1000
Copy link
Collaborator

Choose a reason for hiding this comment

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

The max-module-lines limit was 2000. Should we change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe, we could, but I turned off max line checking in the disable section anyway. report_server.py has more than 4300 lines :)

Comment on lines +467 to +481
duplicate-code, # TODO: Could be eliminated
cyclic-import, # TODO: Could be fixed
subprocess-popen-preexec-fn, # TODO: Could be fixed
broad-exception-caught, # TODO: could be valid
no-member, # TODO: Why is this emitted for multiprocess module?
consider-using-with, # TODO: Mainly for Popen, could be valid
protected-access, # TODO: Used in test code, but not elegant
global-statement,
consider-using-get, # Unnecessary style checker
attribute-defined-outside-init # Too many reports from test codes
Copy link
Collaborator

Choose a reason for hiding this comment

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

The cyclic-import and the no-member checkers used to be enabled explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand, why they didn't report earlier, then. Currently they give reports. I added to TODO for cyclic import, that could be solved sometime. It's interesting, though, that python interpreter doesn't bother about it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand either. OK, we're going to figure it out and solve the cyclic import problem.

Comment on lines +537 to +545
#output-format=

# Tells whether to display a full report or only the messages.
reports=no
Copy link
Collaborator

Choose a reason for hiding this comment

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

We used to set output-format=text and reports=yes. I am not sure it is necessary to change them. Maybe the default value of the output-format is text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's interesting, because some reports are generated even without this option. But you're right. I'll check if there are some local settings in Makefiles for pylint invocations. Now I can see some --ignore and some other configurations in Makefiles, but you're right, every check should use the same configuration. I'll unify pylint calls in makefiles.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for checking it!

@@ -164,7 +164,8 @@ def check_supported_analyzers(analyzers):
failed_analyzers.add((analyzer_name,
"Failed to detect analyzer binary!"))
continue
elif not os.path.isabs(analyzer_bin):

if not os.path.isabs(analyzer_bin):
# If the analyzer is not in an absolute path, try to find it...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why can't we use elif here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can. The checker says that if a continue/break/return/raise/etc. command skips the rest of the block, then it's not necessary to put that block under an "else". I would say, this is a question of style. If we don't agree with this convention, then I can turn off this checker.

@@ -87,7 +87,7 @@ def __check_bug_path_order(self, run_results, order):
def test_get_run_results_no_filter(self):
""" Get all the run results without any filtering. """
runid = self._runid
logging.debug('Get all run results from the db for runid: ' +
logging.debug('Get all run results from the db for runid: %s',
Copy link
Collaborator

Choose a reason for hiding this comment

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

And here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer to use f-string instead of %s format.

@@ -189,7 +189,7 @@ def test_skip(self):
""" There should be no results from the skipped file. """

runid = self._runid
logging.debug('Get all run results from the db for runid: ' +
logging.debug('Get all run results from the db for runid: %s',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer to use f-string instead of %s format.

@@ -237,7 +237,7 @@ def test_suppress_comment_in_db(self):
Exported source suppress comment stored as a review status in the db.
"""
runid = self._runid
logging.debug("Get all run results from the db for runid: " +
logging.debug("Get all run results from the db for runid: %s",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here.

Comment on lines +275 to +281
for run_result in run_results:
logging.debug(run_result)
self.assertIsNotNone(run_results)
self.assertNotEqual(len(run_results), 0)

for bug_hash in hash_to_suppress_msgs:
logging.debug("tesing for bug hash " + bug_hash)
expected_data = hash_to_suppress_msgs[bug_hash]
for bug_hash, expected_data in hash_to_suppress_msgs.items():
logging.debug("tesing for bug hash %s", bug_hash)
Copy link
Collaborator

Choose a reason for hiding this comment

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

And here.

@bruntib
Copy link
Contributor Author

bruntib commented Jul 3, 2024

Thanks for the review, it's a great work at this PR :)

So, would you think, that we should rather allow the "elif" style? Is there any style checker that anyone doesn't agree with? The other common note was about f-strings, but I would say that for the logging library it's reasonable not to use them.

I would wait a little before I go through this change again, so it can be done only once. If no other suggestions arrive, I'll undo "elif" style.

@whisperity
Copy link
Contributor

So, would you think, that we should rather allow the "elif" style?

The general consensus (at least from what I understood from the community posts) is that you should adhere to "no elif after continue/break/return" if the if branch is some sort of an "edge case", where we are basically "early returning".

if not foo:
  log("error")
  return

good_things()

If the two (or all) branches of the if is structurally the "same level", such as when we are translating from an enum to a string or the other way, it's better to have them demarcated by elifs. Especially because Python does not support switch cases. ☹️

if foo == enum.A:
  return "A"
elif foo == enum.B:
  return "B"
# ...

@bruntib bruntib merged commit 981365c into Ericsson:master Jul 8, 2024
7 of 8 checks passed
@bruntib bruntib deleted the pylint_upgrade branch July 8, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config ⚙️ dependencies 📦 Pull requests that update a dependency file dev env ⛑️ Development environment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants