Hello,
I've been digging around the Pylint codebase trying to understand how the scope of enable/disable pragmas is handled.
Several checkers directly reference utils/pragma_parser.py, but the code doesn't seem to go any deeper than checking whether the current line contains a pragma. I can't see that pragma_parser.py is referenced anywhere else in the codebase.
Where is the code for managing scope? Is it hiding under a different name? Is it somehow handled in astroid rather than in Pylint itself?
Thanks for any answers, and thanks for providing such a useful tool!
William Tracy
Hey,
On Fri, Oct 02, 2020 at 06:11:26PM -0700, William Tracy wrote:
Hello,
I've been digging around the Pylint codebase trying to understand how the scope of enable/disable pragmas is handled.
Several checkers directly reference utils/pragma_parser.py, but the code doesn't seem to go any deeper than checking whether the current line contains a pragma. I can't see that pragma_parser.py is referenced anywhere else in the codebase.
Where is the code for managing scope? Is it hiding under a different name? Is it somehow handled in astroid rather than in Pylint itself?
Thanks for any answers, and thanks for providing such a useful tool!
William Tracy
As far as I know, it's all in pylint. The pragma_parser module is used in pylint.lint.pylinter in process_tokens which then calls 'meth'. That is coming from self._options_methods, so for a "# pylint: disable=..." call, that'd be self.disable. That is defined via a mixin in pylint.message.message_handler_mix_in. Via _set_msg_status -> _set_one_msg_status, that calls self.file_state.set_msg_status().
Finally, you'll end up in pylint.utils.file_state where it looks like the answer to your question is in _collect_block_lines.
Florian