MCPcopy
hub / github.com/PyCQA/flake8 / statistics_for

Method statistics_for

src/flake8/statistics.py:37–66  ·  view source on GitHub ↗

Generate statistics for the prefix and filename. If you have a :class:`Statistics` object that has recorded errors, you can generate the statistics for a prefix (e.g., ``E``, ``E1``, ``W50``, ``W503``) with the optional filter of a filename as well. .. code-block::

(
        self, prefix: str, filename: str | None = None
    )

Source from the content-addressed store, hash-verified

35 self._store[key].increment()
36
37 def statistics_for(
38 self, prefix: str, filename: str | None = None
39 ) -> Generator[Statistic]:
40 """Generate statistics for the prefix and filename.
41
42 If you have a :class:`Statistics` object that has recorded errors,
43 you can generate the statistics for a prefix (e.g., ``E``, ``E1``,
44 ``W50``, ``W503``) with the optional filter of a filename as well.
45
46 .. code-block:: python
47
48 >>> stats = Statistics()
49 >>> stats.statistics_for('E12',
50 filename='src/flake8/statistics.py')
51 <generator ...>
52 >>> stats.statistics_for('W')
53 <generator ...>
54
55 :param prefix:
56 The error class or specific error code to find statistics for.
57 :param filename:
58 (Optional) The filename to further filter results by.
59 :returns:
60 Generator of instances of :class:`Statistic`
61 """
62 matching_errors = sorted(
63 key for key in self._store if key.matches(prefix, filename)
64 )
65 for error_code in matching_errors:
66 yield self._store[error_code]
67
68
69class Key(NamedTuple):

Calls 1

matchesMethod · 0.80