Suppose I have an object args
returned by parser.parse_args()
, and it should have attributes like args.port = 6001
, args.seed = 1234
. When I press args.
in VSCode, port
and seed
are not shown in the suggested attribute list, because the attributes might change in runtime. However, the code might have already used args.port
and args.seed
somewhere, so it should be clear that, at least in this scope, args
has attributes port
and seed
. Even though accessing these attributes is not 100% safe, VSCode could add them in the attribute list and indicate that they might be present, rather than not showing them at all. Is there any simple way to tweak VSCode or the Python extension to support this feature? Or, if some other IDE support this feature, I may consider switching to that IDE.
P.S. Why is this necessary? Suppose I’m modifying someone else’s code, and the program has a ton of command-line arguments, which requires the argument names to be rather long, so together with some weird abbreviations, I may need to look up the definition of parser to determine which attribute of args
to use each time. This is very tedious.
P.S. There are some other ways, such as defining a class (say MyClass
) to specify the attributes and write args: MyClass = parser.parse_args()
. But this is also a tedious work to do, especially when the parser is not configured with multiple parser.add_arugment
statements but by several delegate classes scattered in multiple Python files, in which case I need to read all of those files carefully to compose a attribute list.