Skip to content

Conversation

@RhythmP619
Copy link

  • Fixing Pylint W0102 (dangerous default value) warnings by replacing mutable default arguments such as empty lists with None and safely initializing them inside functions. This prevents shared mutable defaults between calls and aligns with Python best practices.
  • Enabling Pylint W0614 (unused wildcard import) checks, which were previously disabled but triggered no errors, to improve static analysis coverage going forward.

Pylint confirms no W0102 warnings remain, and W0614 checks are now active to catch future issues.

@github-actions github-actions bot added Python Related code is in Python libraries labels Nov 26, 2025
RhythmP619 and others added 2 commits November 27, 2025 00:00
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Member

@echoix echoix left a comment

Choose a reason for hiding this comment

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

For all the other changes, like the ones for topolist, I think it would make sense to edit the docstrings to explain that the default value of xxxx is used when None is given (None isn't really an accepted value).
Especially since the function signature doesn't give a clue anymore on this.

Comment on lines +359 to +362
global _MSGR_INSTANCE
if _MSGR_INSTANCE is None:
_MSGR_INSTANCE = Messenger(*args, **kwargs)
return _MSGR_INSTANCE
Copy link
Member

Choose a reason for hiding this comment

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

I don't really like the approach used here. I think it shows well how the previous code was abusing the mutability of the default value, and was affected by it (it was replacing the element at index 0 probably because of that).

However, global variables are usually a source of problems, harder to reason correctly about them. Now, is it worse than the dangerous default value, probably not understood?

I don't understand extremely well the pygrass message module, so I'd like some help here

Copy link
Author

Choose a reason for hiding this comment

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

I agree that the global variable approach can introduce complexity, and the previous code’s mutable default was indeed problematic. My intent was to quickly fix the W0102 issue with a straightforward pattern, but I see the benefit of encapsulating this in a class method or decorator for better clarity and maintainability.

I can update the code to use a class method singleton or a decorator pattern if that’s preferred.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have any special insights to it, but I think this is at least more readable than the previous code. The "instance" parameter doesn't seem to be used anywhere, so I think it's fine to get rid of it.

@echoix echoix requested a review from petrasovaa November 26, 2025 18:33
@RhythmP619
Copy link
Author

Thank you for the detailed feedback!

Regarding the docstrings, I will add clarifications explicitly stating that when the parameter is None, a default list (e.g., ['EQUAL']) is created internally. This should make the behavior clear despite the function signature no longer showing the mutable default.

@RhythmP619 RhythmP619 requested a review from echoix December 1, 2025 17:04
Copy link
Member

@echoix echoix left a comment

Choose a reason for hiding this comment

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

Do you have a better idea for how to only solve what we have here, without addressing the 3041 issues in the gui folder?

Appart from not un commenting it...

Does that rule exist in ruff that could be more easily configured there to help with checking most of the cases?

@echoix
Copy link
Member

echoix commented Dec 2, 2025

Oh, ruff PLW0102 doesn't exist, because B006 is implemented and does the same job. So try making CI pass by enabling B006 (excluding the gui folder)

@petrasovaa
Copy link
Contributor

Do you have a better idea for how to only solve what we have here, without addressing the 3041 issues in the gui folder?

It seems to be about 30 files, I don't know what the 3041 mean.

@echoix
Copy link
Member

echoix commented Dec 4, 2025

Do you have a better idea for how to only solve what we have here, without addressing the 3041 issues in the gui folder?

It seems to be about 30 files, I don't know what the 3041 mean.

Locally, he only ran for the grass package, but we actually have three parts, the grass python api, the tools written in python in the script folder, and the gui.

He solved only in the grass package, but there are lots of remaining issues in the gui folder.

Removing the excluded rule enabled it for everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries Python Related code is in Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants