From 3c885219b56ec5755c44d1649be973ae206806de Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 5 Jan 2022 13:02:38 -0500 Subject: use typesafe NamedTuple --- src/flake8/statistics.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/flake8/statistics.py') 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. """ -- cgit v1.2.1