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

pylintrc: re-enable too-many-arguments #941

Merged

Conversation

xmkg
Copy link
Contributor

@xmkg xmkg commented Jul 12, 2024

started using dataclass types for grouping long list of arguments.

Suppressed the warning for test functions.

@xmkg xmkg requested a review from dosaboy July 12, 2024 12:43
@xmkg xmkg force-pushed the enhancement/pylint-enable-too-many-arguments branch from bcb845d to 5699e5a Compare July 12, 2024 12:50
if minimal_mode:
filtered = self.minimise(filtered, minimal_mode)

if fmt not in self.SUMMARY_FORMATS:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is no longer needed as we now enforce fmt to be one of the values in the SUPPORTED_SUMMARY_FORMATS

@xmkg xmkg force-pushed the enhancement/pylint-enable-too-many-arguments branch from 5699e5a to 050feaf Compare July 18, 2024 07:57
hotsos/client.py Outdated
plugin=None, max_level=2):
if plugin:
filtered = {plugin: self._summary[plugin]}
def get(self, params: OutputManagerParameters = OutputManagerParameters()):
Copy link
Member

Choose a reason for hiding this comment

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

Passing mutable types as param defaults is not a good idea imho for the simple reason that changes (however accidental) to the parameter made during one call of get() will persist to future calls to get(). It would be safer to have the caller pass it in rather than set a default.

Copy link
Member

Choose a reason for hiding this comment

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

from dataclasses import dataclass

@dataclass
class MyOptions:
    flag: bool = False


def foo(flag, opt: MyOptions = MyOptions()):
    if flag:
        opt.flag = True
    else:
        print(opt.flag)

foo(False)
foo(True)
foo(False)

produces

foo(False)
foo(True)
foo(False)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was an interesting gotcha, thanks Ed!

@@ -105,7 +109,8 @@ def stats(self):
s = FileSearcher()
seqdef = SequenceSearchDef(
# match start of interface
start=SearchDef(IP_IFACE_NAME_TEMPLATE.format(self.name)),
start=SearchDef(IP_IFACE_NAME_TEMPLATE.format(
self.name)),
Copy link
Member

Choose a reason for hiding this comment

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

nit: unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed now

@xmkg xmkg force-pushed the enhancement/pylint-enable-too-many-arguments branch 3 times, most recently from cba6bf3 to f6c9a7c Compare July 25, 2024 09:37
ret = self.categorise_events(
event,
results=results,
options=type(self).EventProcessingOptions(key_by_date=False)
Copy link
Member

Choose a reason for hiding this comment

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

nit: it isn't necessary to use type() here?
since this does work either why i wont block on this and can fix in followup patch

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 not necessary, it's just shorter to type type(self). instead of EventProcessingUtils.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I wanted to avoid using self. because it looks like a method call to me, which is not the case. But it might still be confused with a static or class method call, so I doubt the merit of doing that now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced all with "self."

Copy link
Member

Choose a reason for hiding this comment

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

this is why i dont like nested functions and classes ;)

Copy link
Member

Choose a reason for hiding this comment

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

well, that and they are harder to test

hotsos/cli.py Outdated
force, event_tally_granularity, max_logrotate_depth,
max_parallel_tasks, list_plugins, machine_readable, output_path,
command_timeout, sos_unpack_dir, scenario, event, **kwargs):
def cli(*args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

I was concerned that doing this would make it more likely to harder to spot mistakes with ordering of args since they must respect the ordering of decorators but in fact it reduces the risk because the mapping is taken care of by python into the dataclass fields which is kindof nice.

hotsos/cli.py Outdated
@@ -188,7 +189,52 @@ def progress_spinner(show_spinner, path):
thread.join()


def main(): # pylint: disable=R0915
def filter_unexpected_fields(cls):
Copy link
Member

Choose a reason for hiding this comment

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

it took me a few to understand why this is necessary so a docstring is needed here. can followup with a patch to add that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is now incorporated into the CLIArgs class with a docstring.

sys.stdout.write('\n'.join(plugintools.PLUGINS.keys()))
sys.stdout.write('\n')
return

with progress_spinner(not quiet and not debug, drm.name):
with progress_spinner(
not arguments.quiet and not arguments.debug, drm.name):
plugins = []
Copy link
Member

Choose a reason for hiding this comment

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

This is now unfortunately broken. we were using kwargs that were not explicitly defined i.e. from (**kwargs) as plugin names to be run and since almost everything is now in kwargs this now blows up when you use any on the command line. We therefore need to find a way to identify plugin names in kwargs - maybe could pull the nested new_init() function out of filter_unexpected_field() and generalise it to use for this purpose also.

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 catch, I'll fix it shortly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be good to go.

@xmkg xmkg force-pushed the enhancement/pylint-enable-too-many-arguments branch 2 times, most recently from 57d8e6d to b1c57e4 Compare July 29, 2024 08:13
started using dataclass types for grouping long list of arguments.

Suppressed the warning for test functions.

Signed-off-by: Mustafa Kemal Gilor <[email protected]>
@xmkg xmkg force-pushed the enhancement/pylint-enable-too-many-arguments branch from b1c57e4 to 141e069 Compare July 29, 2024 08:29
Copy link
Member

@dosaboy dosaboy left a comment

Choose a reason for hiding this comment

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

lgtm

@dosaboy dosaboy merged commit 8d9e0e9 into canonical:main Jul 29, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants