- Deleted obsolete test files related to `Any` usage and `type: ignore` checks to streamline the codebase. - Introduced new modules for message enrichment and type inference to improve error messaging and type suggestion capabilities in hooks. - Updated `pyproject.toml` and `pyrightconfig.json` to include new dependencies and configurations for enhanced type checking. - Improved the quality check mechanisms in the hooks to provide more detailed feedback and guidance on code quality issues.
230 lines
9.4 KiB
Python
230 lines
9.4 KiB
Python
"""
|
|
This type stub file was generated by pyright.
|
|
"""
|
|
|
|
import inspect
|
|
import os
|
|
import sys
|
|
import tomllib
|
|
import radon.complexity as cc_mod
|
|
import configparser
|
|
from contextlib import contextmanager
|
|
from mando import Program
|
|
from radon.cli.colors import BRIGHT, RED, RESET
|
|
from radon.cli.harvest import CCHarvester, HCHarvester, MIHarvester, RawHarvester
|
|
|
|
'''In this module the CLI interface is created.'''
|
|
TOMLLIB_PRESENT = ...
|
|
if sys.version_info[0] == 2:
|
|
...
|
|
else:
|
|
...
|
|
CONFIG_SECTION_NAME = ...
|
|
class FileConfig:
|
|
'''
|
|
Yield default options by reading local configuration files.
|
|
'''
|
|
def __init__(self) -> None:
|
|
...
|
|
|
|
def get_value(self, key, type, default): # -> int | bool | str:
|
|
...
|
|
|
|
@staticmethod
|
|
def toml_config(): # -> dict[Any, Any] | Any:
|
|
...
|
|
|
|
@staticmethod
|
|
def file_config(): # -> ConfigParser:
|
|
'''Return any file configuration discovered'''
|
|
...
|
|
|
|
|
|
|
|
_cfg = ...
|
|
program = ...
|
|
@program.command
|
|
@program.arg('paths', nargs='+')
|
|
def cc(paths, min=..., max=..., show_complexity=..., average=..., exclude=..., ignore=..., order=..., json=..., no_assert=..., show_closures=..., total_average=..., xml=..., md=..., codeclimate=..., output_file=..., include_ipynb=..., ipynb_cells=...): # -> None:
|
|
'''Analyze the given Python modules and compute Cyclomatic
|
|
Complexity (CC).
|
|
|
|
The output can be filtered using the *min* and *max* flags. In addition
|
|
to that, by default complexity score is not displayed.
|
|
|
|
:param paths: The paths where to find modules or packages to analyze. More
|
|
than one path is allowed.
|
|
:param -n, --min <str>: The minimum complexity to display (default to A).
|
|
:param -x, --max <str>: The maximum complexity to display (default to F).
|
|
:param -e, --exclude <str>: Exclude files only when their path matches one
|
|
of these glob patterns. Usually needs quoting at the command line.
|
|
:param -i, --ignore <str>: Ignore directories when their name matches one
|
|
of these glob patterns: radon won't even descend into them. By default,
|
|
hidden directories (starting with '.') are ignored.
|
|
:param -s, --show-complexity: Whether or not to show the actual complexity
|
|
score together with the A-F rank. Default to False.
|
|
:param -a, --average: If True, at the end of the analysis display the
|
|
average complexity. Default to False.
|
|
:param --total-average: Like `-a, --average`, but it is not influenced by
|
|
`min` and `max`. Every analyzed block is counted, no matter whether it
|
|
is displayed or not.
|
|
:param -o, --order <str>: The ordering function. Can be SCORE, LINES or
|
|
ALPHA.
|
|
:param -j, --json: Format results in JSON.
|
|
:param --xml: Format results in XML (compatible with CCM).
|
|
:param --md: Format results in Markdown.
|
|
:param --codeclimate: Format results for Code Climate.
|
|
:param --no-assert: Do not count `assert` statements when computing
|
|
complexity.
|
|
:param --show-closures: Add closures/inner classes to the output.
|
|
:param -O, --output-file <str>: The output file (default to stdout).
|
|
:param --include-ipynb: Include IPython Notebook files
|
|
:param --ipynb-cells: Include reports for individual IPYNB cells
|
|
'''
|
|
...
|
|
|
|
@program.command
|
|
@program.arg('paths', nargs='+')
|
|
def raw(paths, exclude=..., ignore=..., summary=..., json=..., output_file=..., include_ipynb=..., ipynb_cells=...): # -> None:
|
|
'''Analyze the given Python modules and compute raw metrics.
|
|
|
|
:param paths: The paths where to find modules or packages to analyze. More
|
|
than one path is allowed.
|
|
:param -e, --exclude <str>: Exclude files only when their path matches one
|
|
of these glob patterns. Usually needs quoting at the command line.
|
|
:param -i, --ignore <str>: Ignore directories when their name matches one
|
|
of these glob patterns: radon won't even descend into them. By default,
|
|
hidden directories (starting with '.') are ignored.
|
|
:param -s, --summary: If given, at the end of the analysis display the
|
|
summary of the gathered metrics. Default to False.
|
|
:param -j, --json: Format results in JSON. Note that the JSON export does
|
|
not include the summary (enabled with `-s, --summary`).
|
|
:param -O, --output-file <str>: The output file (default to stdout).
|
|
:param --include-ipynb: Include IPython Notebook files
|
|
:param --ipynb-cells: Include reports for individual IPYNB cells
|
|
'''
|
|
...
|
|
|
|
@program.command
|
|
@program.arg('paths', nargs='+')
|
|
def mi(paths, min=..., max=..., multi=..., exclude=..., ignore=..., show=..., json=..., sort=..., output_file=..., include_ipynb=..., ipynb_cells=...): # -> None:
|
|
'''Analyze the given Python modules and compute the Maintainability Index.
|
|
|
|
The maintainability index (MI) is a compound metric, with the primary aim
|
|
being to determine how easy it will be to maintain a particular body of
|
|
code.
|
|
|
|
:param paths: The paths where to find modules or packages to analyze. More
|
|
than one path is allowed.
|
|
:param -n, --min <str>: The minimum MI to display (default to A).
|
|
:param -x, --max <str>: The maximum MI to display (default to C).
|
|
:param -e, --exclude <str>: Exclude files only when their path matches one
|
|
of these glob patterns. Usually needs quoting at the command line.
|
|
:param -i, --ignore <str>: Ignore directories when their name matches one
|
|
of these glob patterns: radon won't even descend into them. By default,
|
|
hidden directories (starting with '.') are ignored.
|
|
:param -m, --multi: If given, multiline strings are not counted as
|
|
comments.
|
|
:param -s, --show: If given, the actual MI value is shown in results.
|
|
:param -j, --json: Format results in JSON.
|
|
:param --sort: If given, results are sorted in ascending order.
|
|
:param -O, --output-file <str>: The output file (default to stdout).
|
|
:param --include-ipynb: Include IPython Notebook files
|
|
:param --ipynb-cells: Include reports for individual IPYNB cells
|
|
'''
|
|
...
|
|
|
|
@program.command
|
|
@program.arg("paths", nargs="+")
|
|
def hal(paths, exclude=..., ignore=..., json=..., functions=..., output_file=..., include_ipynb=..., ipynb_cells=...): # -> None:
|
|
"""
|
|
Analyze the given Python modules and compute their Halstead metrics.
|
|
|
|
The Halstead metrics are a series of measurements meant to quantitatively
|
|
measure the complexity of code, including the difficulty a programmer would
|
|
have in writing it.
|
|
|
|
:param paths: The paths where to find modules or packages to analyze. More
|
|
than one path is allowed.
|
|
:param -e, --exclude <str>: Exclude files only when their path matches one
|
|
of these glob patterns. Usually needs quoting at the command line.
|
|
:param -i, --ignore <str>: Ignore directories when their name matches one
|
|
of these glob patterns: radon won't even descend into them. By default,
|
|
hidden directories (starting with '.') are ignored.
|
|
:param -j, --json: Format results in JSON.
|
|
:param -f, --functions: Analyze files by top-level functions instead of as
|
|
a whole.
|
|
:param -O, --output-file <str>: The output file (default to stdout).
|
|
:param --include-ipynb: Include IPython Notebook files
|
|
:param --ipynb-cells: Include reports for individual IPYNB cells
|
|
"""
|
|
...
|
|
|
|
class Config:
|
|
'''An object holding config values.'''
|
|
def __init__(self, **kwargs) -> None:
|
|
'''Configuration values are passed as keyword parameters.'''
|
|
...
|
|
|
|
def __getattr__(self, attr): # -> Any:
|
|
'''If an attribute is not found inside the config values, the request
|
|
is handed to `__getattribute__`.
|
|
'''
|
|
...
|
|
|
|
def __repr__(self): # -> str:
|
|
'''The string representation of the Config object is just the one of
|
|
the dictionary holding the configuration values.
|
|
'''
|
|
...
|
|
|
|
def __eq__(self, other) -> bool:
|
|
'''Two Config objects are equals if their contents are equal.'''
|
|
...
|
|
|
|
@classmethod
|
|
def from_function(cls, func): # -> Self:
|
|
'''Construct a Config object from a function's defaults.'''
|
|
...
|
|
|
|
|
|
|
|
def log_result(harvester, **kwargs): # -> None:
|
|
'''Log the results of an :class:`~radon.cli.harvest.Harvester object.
|
|
|
|
Keywords parameters determine how the results are formatted. If *json* is
|
|
`True`, then `harvester.as_json()` is called. If *xml* is `True`, then
|
|
`harvester.as_xml()` is called. If *codeclimate* is True, then
|
|
`harvester.as_codeclimate_issues()` is called.
|
|
Otherwise, `harvester.to_terminal()` is executed and `kwargs` is directly
|
|
passed to the :func:`~radon.cli.log` function.
|
|
'''
|
|
...
|
|
|
|
def log(msg, *args, **kwargs): # -> None:
|
|
'''Log a message, passing *args* to the strings' `format()` method.
|
|
|
|
*indent*, if present as a keyword argument, specifies the indent level, so
|
|
that `indent=0` will log normally, `indent=1` will indent the message by 4
|
|
spaces, &c..
|
|
*noformat*, if present and True, will cause the message not to be formatted
|
|
in any way.
|
|
'''
|
|
...
|
|
|
|
def log_list(lst, *args, **kwargs): # -> None:
|
|
'''Log an entire list, line by line. All the arguments are directly passed
|
|
to :func:`~radon.cli.log`.
|
|
'''
|
|
...
|
|
|
|
def log_error(msg, *args, **kwargs): # -> None:
|
|
'''Log an error message. Arguments are the same as log().'''
|
|
...
|
|
|
|
@contextmanager
|
|
def outstream(outfile=...): # -> Generator[TextIOWrapper[_WrappedBuffer] | TextIO | Any, Any, None]:
|
|
'''Encapsulate output stream creation as a context manager'''
|
|
...
|
|
|