Open Pierre-Sassoulas opened 1 year ago
This means unconditionally flagging any use of sys.argv
and suggesting argparse
instead?
This very arbitrary and something that I would normally advise to make as a plug-in.
As a hack you could also use suggested-module
with a non sensical replacement value.
Yes, it's clearly an optional extension candidate.
any use of sys.argv and suggesting argparse instead?
Not sys.argv
alone, but any access of sys.argv
using indexes or range, like my_arg = sys.argv[2]
, a, b, c = sys.argv[1:]
. (and suggest 'argparse or another arg parsing library')
As a hack you could also use suggested-module with a non sensical replacement value.
I did not understand that part, I don't think we have a suggested-module
option ?
--preferred-modules
😄
https://pylint.pycqa.org/en/latest/user_guide/messages/warning/preferred-module.html
I liked the idea but preferred-module
is checking at import time so this can't work atm:
[IMPORTS]
preferred-modules=json:ujson,re:regex,sys.argv:argparse;
"""Test preferred modules."""
# pylint: disable=unused-import
import json # [preferred-module]
import sys
from re import search # [preferred-module]
print(sys.argv[1:3]) # [preferred-module] <= not raised
Ah, I misremembered https://github.com/PyCQA/pylint/pull/8186
If sys.argv is accessed directly it means you're not going to have the same level of support for errors than a dedicated library, and argparse is such a lib that is a builtin lib since python 3.2.
Originally posted by @Pierre-Sassoulas in https://github.com/PyCQA/pylint/issues/7710#issuecomment-1450254075