MCPcopy Create free account
hub / github.com/PyCQA/flake8 / Key

Class Key

src/flake8/statistics.py:69–99  ·  view source on GitHub ↗

Simple key structure for the Statistics dictionary. To make things clearer, easier to read, and more understandable, we use a namedtuple here for all Keys in the underlying dictionary for the Statistics object.

Source from the content-addressed store, hash-verified

67
68
69class Key(NamedTuple):
70 """Simple key structure for the Statistics dictionary.
71
72 To make things clearer, easier to read, and more understandable, we use a
73 namedtuple here for all Keys in the underlying dictionary for the
74 Statistics object.
75 """
76
77 filename: str
78 code: str
79
80 @classmethod
81 def create_from(cls, error: Violation) -> Key:
82 """Create a Key from :class:`flake8.violation.Violation`."""
83 return cls(filename=error.filename, code=error.code)
84
85 def matches(self, prefix: str, filename: str | None) -> bool:
86 """Determine if this key matches some constraints.
87
88 :param prefix:
89 The error code prefix that this key's error code should start with.
90 :param filename:
91 The filename that we potentially want to match on. This can be
92 None to only match on error prefix.
93 :returns:
94 True if the Key's code starts with the prefix and either filename
95 is None, or the Key's filename matches the value passed in.
96 """
97 return self.code.startswith(prefix) and (
98 filename is None or self.filename == filename
99 )
100
101
102class Statistic:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected