diff options
author | Anthony Sottile <asottile@umich.edu> | 2022-01-05 13:02:38 -0500 |
---|---|---|
committer | Anthony Sottile <asottile@umich.edu> | 2022-01-05 13:02:38 -0500 |
commit | 3c885219b56ec5755c44d1649be973ae206806de (patch) | |
tree | 3cae12eaebc3dc0d4049a8a5d0871fc204b2d70a /src/flake8/statistics.py | |
parent | f0fb7868832486091e26072e53ead5e50bdf3e64 (diff) | |
download | flake8-new_namedtuple.tar.gz |
use typesafe NamedTuplenew_namedtuple
Diffstat (limited to 'src/flake8/statistics.py')
-rw-r--r-- | src/flake8/statistics.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/flake8/statistics.py b/src/flake8/statistics.py index 073bfe4..ad93c8f 100644 --- a/src/flake8/statistics.py +++ b/src/flake8/statistics.py @@ -1,8 +1,8 @@ """Statistic collection logic for Flake8.""" -import collections from typing import Dict from typing import Generator from typing import List +from typing import NamedTuple from typing import Optional from typing import TYPE_CHECKING @@ -73,7 +73,7 @@ class Statistics: yield self._store[error_code] -class Key(collections.namedtuple("Key", ["filename", "code"])): +class Key(NamedTuple): """Simple key structure for the Statistics dictionary. To make things clearer, easier to read, and more understandable, we use a @@ -81,7 +81,8 @@ class Key(collections.namedtuple("Key", ["filename", "code"])): Statistics object. """ - __slots__ = () + filename: str + code: str @classmethod def create_from(cls, error: "Violation") -> "Key": @@ -111,7 +112,7 @@ class Statistic: """Simple wrapper around the logic of each statistic. Instead of maintaining a simple but potentially hard to reason about - tuple, we create a namedtuple which has attributes and a couple + tuple, we create a class which has attributes and a couple convenience methods on it. """ |