I originally asked the following question on Stack Overflow<http://stackoverflow.com/questions/18500998/extending-pylint-to-deal-with-template-variables>. It was suggested that this would be the better venue for discussion.
-- I wrote the say <https://pypi.python.org/pypi/say> module to make formatted printing simpler and more straightforward. E.g. say("{len(items)} retrieved; {n_errors} encountered") rather than: print("{0} retrieved; {1} encountered".format(len(items), n_errors)) That part is going great. But I like to run pylint to look for gotchas and mistakes. Unfortunately, many data values are constructed solely for their usefulness in output operations, and pylint cannot "see" that use in a say call (or any other templates output mechanism) constitutes a genuine use of the variable. Wave after wave of W0612 (unused-variable) warnings can result. It's possible to simply put in ignore comments, but that seems retrograde. I'd rather just extend pylint to understand that variables used in say() templates are, in fact, used. .../pylint/checkers/variables.py appears to be the place to add this check, but I'm unfamiliar with the codebase. Any hints or suggestions as to how to register variables used in format-style strings are, indeed, properly used? -- One SO commenter suggested that since pylint doesn't do much with strings, this may be a fair amount of work. But I already know how to parse format-style strings; I just use Python's own string.Formatter.parse. Creating an AST from the contents of the format braces and walking it to find what names are referenced--I've got that covered. What I most need is insight into how to communicate to pylint that it should consider the identifiers I've found to be used. I'd also seen at least one comment online suggesting that pylint doesn't really have an extensions/plugin mechanism. Is that true? Either way, what would be the best way to provide extended functionality atop pylint? Is the team receptive to code contributions?
_______________________________________________ code-quality mailing list code-quality@python.org http://mail.python.org/mailman/listinfo/code-quality