fix(lint): tune pylintrc and fix violations across core modules#1793
fix(lint): tune pylintrc and fix violations across core modules#1793ppradyoth wants to merge 1 commit into
Conversation
Addresses the issues catalogued in NVIDIA#1792. This is the draft standard requested by the maintainer — it fixes genuine violations, documents intentional exceptions with inline suppressions, and removes the unrecognized `suggestion-mode` option so the linting workflow can be enabled for CI runs. Changes by file: pylintrc - Remove `suggestion-mode=yes` (option removed in pylint 3.x; was causing E0015 "unrecognized-option" on every run) - Add `too-many-positional-arguments` to the disable list (consistent with the existing `too-many-arguments` exemption) - Add `Director` to `ignored-classes` (payload_list is a dynamic class attribute that pylint cannot infer as a dict at static-analysis time) garak/exception.py - Add missing module docstring (C0114) garak/command.py - Add docstrings to all public functions (C0116) - Remove unused `plugin_info as get_plugin_info` alias from the import inside `print_plugins` — it is imported again inside `_print_plugins_table` where it is actually used (W0611) - Suppress `broad-exception-caught` in `end_run` with explanation: report-building failures must not crash the CLI (W0718) - Suppress `no-member` on `cli_args` attribute access: `TransientConfig` sets these dynamically via argparse (E1101) garak/configurable.py - Add missing module and class docstrings (C0114, C0115); class docstring explains the ENV_VAR dynamic attribute pattern - Fix logging f-string to use %s lazy formatting (W1203) - Suppress `no-member` on `self.ENV_VAR` — defined by subclasses (E1101) - Suppress `unsupported-membership-test` on `_supported_params` — guarded by isinstance check above (E1135) - Suppress `access-member-before-definition` on `api_key` — intentional lazy-set pattern (E0203) garak/interactive.py - Add missing module docstring (C0114) - Add missing class docstring for GarakCommands (C0115) - Add docstrings to print_plugins, do_list, do_probe, do_quit (C0116) - Replace set-from-list-comprehension with set comprehension (R1718) - Fix logging f-string to use %s lazy formatting (W1203) - Make all return statements in do_probe consistent (R1710) - Remove f-string without interpolation in default() (W1309) - Rename unused cmd2 interface params to _command/_line/_args (W0613) - Suppress `no-member` on self.settings — cmd2.Cmd sets it dynamically garak/payloads.py - Fix import order: stdlib before third-party (C0411) - Add docstrings to module-level search() and load() (C0116) - Suppress `not-an-iterable` and `unsubscriptable-object` in Director.search/load — payload_list is None at class level but guaranteed to be a dict after _refresh_payloads() (E1133, E1136) garak/_config.py - Add missing class docstring for GarakSubConfig (C0115) - Add docstrings to _store_config, _garak_user_agent, set_all_http_lib_agents, set_http_lib_agents, get_http_lib_agents, load_base_config, load_config, parse_plugin_spec (C0116) - Fix all logging f-strings to use %s lazy formatting (W1203) - Rename dummy parameter to _dummy in _garak_user_agent (W0613) - Remove unnecessary else after raise in load_config (R1705) - Fix any() to use generator instead of list (R1729) - Add pylint: disable=global-statement comments on intentional global usage — _config is a module-level singleton and globals are by design garak/report.py - Fix import order: stdlib (datetime) before third-party (C0411) - Replace range(len(evals)) with direct iteration (C0200) - Suppress comparison-with-itself (all_tags == all_tags) — this is the standard pandas NaN sentinel check; NaN != NaN (R0124) Signed-off-by: ppradyoth <pradyoth0@gmail.com>
Remaining violations after this PRRunning Here's the breakdown by type to help prioritise the next passes:
The 640 The remaining ~400 violations are largely mechanical and can be addressed file-by-file. I can batch them up as follow-on PRs once this draft standard is agreed. |
Suggested next steps after this draftI think the cleanest path is to keep this PR focused on establishing the linting baseline and fixing the concrete violations in the touched core files, then handle the larger remaining reduction as follow-up work once maintainers agree on policy. A local before/after count with
The biggest remaining bucket is
For the CI gate, my recommendation is to start with an agreed baseline/exit-code gate rather than a broad score threshold. A score threshold can still allow new important errors through if the aggregate score remains high enough. I would also suggest enabling the linting workflow in a follow-up PR after the dynamic-attribute policy is agreed, so this PR can stay reviewable and serve as the draft standard requested in #1792. |
Summary
This is the draft standard requested in #1792. It fixes genuine pylint violations, documents intentional exceptions with inline suppressions, and removes the unrecognised
suggestion-modeoption — so the Garak linting workflow can be enabled for CI runs.Every suppression has a comment explaining why it is intentional. Happy to iterate on any of these in review.
Changes
pylintrcsuggestion-mode=yes— removed in pylint 3.x, causedE0015on every runtoo-many-positional-argumentsto disable list (consistent with existingtoo-many-argumentsexemption)Directortoignored-classes—payload_listis dynamic and cannot be inferred at static-analysis timegarak/exception.py— add module docstringgarak/command.pyplugin_info as get_plugin_infoimport alias insideprint_pluginsbroad-exception-caughtinend_run— report failures must not crash the CLIno-memberoncli_args— set dynamically by argparsegarak/configurable.pyENV_VARdynamic attribute pattern%slazy formattingno-memberonself.ENV_VAR— defined by subclasses (as confirmed in Linting CI fails on main due to pre-existing pylint violations #1792)unsupported-membership-teston_supported_params— guarded byisinstanceaboveaccess-member-before-definitiononapi_key— intentional lazy-set patterngarak/interactive.pydo_probe_command/_line/_argsno-memberonself.settings— set dynamically bycmd2.Cmdgarak/payloads.pysearch()andload()not-an-iterable/unsubscriptable-objectinDirector—payload_listisNoneat class level but always a dict after_refresh_payloads()garak/_config.pydummy→_dummyin_garak_user_agent(required by requests UA callback signature)elifafterraiseany()instead of list# pylint: disable=global-statementwith explanations —_configis a module-level singleton by designgarak/report.pydatetime) before third-partyrange(len(evals))with direct iterationcomparison-with-itselfonall_tags == all_tags— standard pandas NaN sentinelTest plan
pylint --rcfile=pylintrc garak/— no new errors on changed filespytest tests/passes — no behaviour changes, docstrings/style onlyOpen questions for maintainers
generated-membersorignored-classes?Closes #1792