class PyLinter(_ArgumentsManager, _MessageStateHandler, reporters.ReportsHandlerMixIn, checkers.BaseChecker): (source)
Known subclasses: pylint.testutils.UnittestLinter
Lint Python modules using external checkers. This is the main checker controlling the other ones and the reports generation. It is itself both a raw checker and an astroid checker in order to: * handle message activation / deactivation at the module level * handle some basic but necessary stats' data (number of classes, methods...) IDE plugin developers: you may have to call `astroid.MANAGER.clear_cache()` across runs if you want to ensure the latest code version is actually checked. This class needs to support pickling for parallel linting to work. The exception is reporter member; see check_parallel function for more details.
Static Method | should |
Returns whether a module should be checked. |
Method | __init__ |
Undocumented |
Method | add |
Prepares a message to be added to the ignored message storage. |
Method | add |
Adds a message given by ID or name. |
Method | any |
Undocumented |
Method | check |
Main checking entry: check a list of files or modules from their name. |
Method | check |
Check a module from its astroid representation. |
Method | check |
Undocumented |
Method | check |
Check single file item. |
Method | disable |
Disable all reporters. |
Method | enable |
Enable 'fail on' msgs. |
Method | generate |
Close the whole package /module, it's time to make reports ! |
Method | get |
Return an ast(roid) representation of a module or a string. |
Method | get |
Get all the checker names that this linter knows about. |
Method | get |
Return all available checkers as an ordered list. |
Method | initialize |
Initialize linter for linting. |
Method | load |
Undocumented |
Method | load |
Call the configuration hook for plugins. |
Method | load |
Check a list of pylint plugins modules, load and register them. |
Method | open |
Initialize counters. |
Method | option |
Undocumented |
Method | prepare |
Return checkers needed for activated messages and reports. |
Method | register |
This method auto registers the checker. |
Method | register |
Registers a reporter class on the _reporters attribute. |
Method | report |
Return a list of reporters. |
Method | set |
Set the name of the currently analyzed module and init statistics for it. |
Method | set |
Set the reporter used to display messages and reports. |
Class Variable | crash |
Undocumented |
Class Variable | option |
Undocumented |
Instance Variable | config |
Undocumented |
Instance Variable | current |
Undocumented |
Instance Variable | current |
Undocumented |
Instance Variable | fail |
List of message symbols on which pylint should fail, set by --fail-on. |
Instance Variable | file |
Undocumented |
Instance Variable | msg |
Undocumented |
Instance Variable | msgs |
Undocumented |
Instance Variable | options |
Undocumented |
Instance Variable | reporter |
Undocumented |
Instance Variable | reports |
Undocumented |
Instance Variable | stats |
Undocumented |
Property | option |
Undocumented |
Method | _add |
After various checks have passed a single Message is passed to the reporter and added to stats. |
Method | _astroid |
Context manager for checking ASTs. |
Method | _check |
Check given AST node with given walker and checkers. |
Method | _check |
Check a file using the passed utility functions (get_ast and check_astroid_module). |
Method | _discover |
Discover python modules and packages in sub-directory. |
Method | _emit |
Undocumented |
Method | _expand |
Get modules and errors from a list of modules and handle errors. |
Method | _get |
Get the AST for all given FileItems. |
Method | _get |
Return file description (tuple of module name, file path, base name) from given file path. |
Method | _get |
Undocumented |
Method | _iterate |
Return generator yielding file descriptions (tuples of module name, file path, base name). |
Method | _lint |
Lint a file using the passed utility function check_astroid_module). |
Method | _lint |
Lint all AST modules from a mapping.. |
Method | _load |
Undocumented |
Method | _load |
Load the reporters if they are available on _reporters. |
Method | _parse |
Parse the current state of the error mode. |
Method | _report |
Make the global evaluation report. |
Instance Variable | _by |
Undocumented |
Instance Variable | _checkers |
Dictionary of registered and initialized checkers. |
Instance Variable | _dynamic |
Set of loaded plugin names. |
Instance Variable | _error |
Undocumented |
Instance Variable | _ignore |
Undocumented |
Instance Variable | _ignore |
Undocumented |
Instance Variable | _option |
Undocumented |
Instance Variable | _reporters |
Dictionary of possible but non-initialized reporters. |
Instance Variable | _stashed |
Some messages in the options (for --enable and --disable) are encountered too early to warn about them. |
Inherited from _MessageStateHandler
:
Method | disable |
Disable a message for a scope. |
Method | disable |
Disable a message for the next line. |
Method | disable |
Disable message categories other than `error` and `fatal`. |
Method | enable |
Enable a message for a scope. |
Method | is |
Return whether this message is enabled for the current file, line and confidence level. |
Method | list |
Undocumented |
Method | process |
Process tokens from the current module to search for module/block level options. |
Instance Variable | linter |
Undocumented |
Method | _get |
Returns the scope at which a message was enabled/disabled. |
Method | _get |
Do some tests and find the actual messages of which the status should be set. |
Method | _is |
Checks state of a single message for the current file. |
Method | _register |
If the msgid is a numeric one, then register it to inform the user it could furnish instead a symbolic msgid. |
Method | _set |
Do some tests and then iterate over message definitions to set state. |
Method | _set |
Set the status of an individual message. |
Instance Variable | _bw |
Undocumented |
Instance Variable | _msgs |
Undocumented |
Instance Variable | _options |
Undocumented |
Instance Variable | _pragma |
Undocumented |
Inherited from ReportsHandlerMixIn
(via _MessageStateHandler
):
Method | disable |
Disable the report of the given id. |
Method | enable |
Enable the report of the given id. |
Method | make |
Render registered reports. |
Method | register |
Register a report. |
Method | report |
Is the report associated to the given identifier enabled ? |
Instance Variable | _reports |
Undocumented |
Instance Variable | _reports |
Undocumented |
def should_analyze_file(modname:
str
, path: str
, is_argument: bool
= False) -> bool
:
(source)
¶
Returns whether a module should be checked. This implementation returns True for all python source file, indicating that all files should be linted. Subclasses may override this method to indicate that modules satisfying certain conditions should not be linted. :param str modname: The name of the module to be checked. :param str path: The full path to the source code of the module. :param bool is_argument: Whether the file is an argument to pylint or not. Files which respect this property are always checked, since the user requested it explicitly. :returns: True if the module should be checked.
Options
= (), reporter: (reporters.BaseReporter|reporters.MultiReporter)|None
= None, option_groups: tuple[ tuple[ str, str], ...]
= (), pylintrc: str|None
= None):
(source)
¶
pylint.testutils.UnittestLinter
Undocumented
str
, line: int
, node: nodes.NodeNG|None
= None, confidence: interfaces.Confidence|None
= interfaces.UNDEFINED):
(source)
¶
Prepares a message to be added to the ignored message storage. Some checks return early in special cases and never reach add_message(), even though they would normally issue a message. This creates false positives for useless-suppression. This function avoids this by adding those message to the ignored msgs attribute
str
, line: int|None
= None, node: nodes.NodeNG|None
= None, args: Any|None
= None, confidence: interfaces.Confidence|None
= None, col_offset: int|None
= None, end_lineno: int|None
= None, end_col_offset: int|None
= None):
(source)
¶
pylint.testutils.UnittestLinter
Adds a message given by ID or name. If provided, the message string is expanded using args. AST checkers must provide the node argument (but may optionally provide line if the line number is different), raw and token checkers must provide the line argument.
Main checking entry: check a list of files or modules from their name. files_or_modules is either a string or list of strings presenting modules to check.
nodes.Module
, walker: ASTWalker
, rawcheckers: list[ checkers.BaseRawFileChecker]
, tokencheckers: list[ checkers.BaseTokenChecker]
) -> bool|None
:
(source)
¶
Check a module from its astroid representation. For return value see _check_astroid_module
Check single file item. The arguments are the same that are documented in _check_files initialize() should be called before calling this method
Enable 'fail on' msgs. Convert values in config.fail_on (which might be msg category, msg id, or symbol) to specific msgs, then enable and flag them for later.
Close the whole package /module, it's time to make reports ! if persistent run, pickle results for later comparison
str
, modname: str
, data: str|None
= None) -> nodes.Module|None
:
(source)
¶
Return an ast(roid) representation of a module or a string. :param filepath: path to checked file. :param str modname: The name of the module to be checked. :param str data: optional contents of the checked file. :returns: the AST :rtype: astroid.nodes.Module :raises AstroidBuildingError: Whenever we encounter an unexpected exception
Call the configuration hook for plugins. This walks through the list of plugins, grabs the "load_configuration" hook, if exposed, and calls it to allow plugins to configure specific settings. The result of attempting to load the plugin of the given name is stored in the dynamic plugins dictionary in ``load_plugin_modules`` above. ..note:: This function previously always tried to load modules again, which led to some confusion and silent failure conditions as described in GitHub issue #7264. Making it use the stored result is more efficient, and means that we avoid the ``init-hook`` problems from before.
Check a list of pylint plugins modules, load and register them. If a module cannot be loaded, never try to load it again and instead store the error message for later use in ``load_plugin_configuration`` below.
MessageDefinition
, line: int|None
, node: nodes.NodeNG|None
, args: Any|None
, confidence: interfaces.Confidence|None
, col_offset: int|None
, end_lineno: int|None
, end_col_offset: int|None
):
(source)
¶
After various checks have passed a single Message is passed to the reporter and added to stats.
def _astroid_module_checker(self) ->
Iterator[ Callable[ [ nodes.Module], bool|None]]
:
(source)
¶
Context manager for checking ASTs. The value in the context is callable accepting AST as its only argument.
nodes.Module
, walker: ASTWalker
, rawcheckers: list[ checkers.BaseRawFileChecker]
, tokencheckers: list[ checkers.BaseTokenChecker]
) -> bool|None
:
(source)
¶
Check given AST node with given walker and checkers. :param astroid.nodes.Module node: AST node of the module to check :param pylint.utils.ast_walker.ASTWalker walker: AST walker :param list rawcheckers: List of token checkers to use :param list tokencheckers: List of raw checkers to use :returns: True if the module was checked, False if ignored, None if the module contents could not be parsed
GetAstProtocol
, check_astroid_module: Callable[ [ nodes.Module], bool|None]
, file: FileItem
):
(source)
¶
Check a file using the passed utility functions (get_ast and check_astroid_module). :param callable get_ast: callable returning AST from defined file taking the following arguments - filepath: path to the file to check - name: Python module name :param callable check_astroid_module: callable checking an AST taking the following arguments - ast: AST of the module :param FileItem file: data about the file :raises AstroidError: for any failures stemming from astroid
Discover python modules and packages in sub-directory. Returns iterator of paths to discovered modules and packages.
Sequence[ str]
) -> dict[ str, ModuleDescriptionDict]
:
(source)
¶
Get modules and errors from a list of modules and handle errors.
Iterator[ FileItem]
, data: str|None
) -> dict[ FileItem, nodes.Module|None]
:
(source)
¶
Get the AST for all given FileItems.
Return file description (tuple of module name, file path, base name) from given file path. This method is used for creating suitable file description for _check_files when the source is standard input.
Path
, namespaces: DirectoryNamespaceDict
) -> argparse.Namespace|None
:
(source)
¶
Undocumented
Return generator yielding file descriptions (tuples of module name, file path, base name). The returned generator yield one item for each Python module that should be linted.
FileItem
, module: nodes.Module
, check_astroid_module: Callable[ [ nodes.Module], bool|None]
):
(source)
¶
Lint a file using the passed utility function check_astroid_module). :param FileItem file: data about the file :param nodes.Module module: the ast module to lint :param Callable check_astroid_module: callable checking an AST taking the following arguments - ast: AST of the module :raises AstroidError: for any failures stemming from astroid
dict[ FileItem, nodes.Module|None]
, check_astroid_module: Callable[ [ nodes.Module], bool|None]
):
(source)
¶
Lint all AST modules from a mapping..
Parse the current state of the error mode. Error mode: enable only errors; no reports, no persistent.