From 4e5df0b0abfda83049eba1eb202ce85bceb6f58d Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 8 Jun 2023 20:57:23 -0400 Subject: switch from collections.namedtuple to typing.NamedTuple Minor cleanup to use better style & typing info. Bug: None Test: unittests Change-Id: I6e80c0ea07e5db1acebb8d17945dd31c3b302134 --- rh/__init__.py | 12 +++++++++--- rh/hooks.py | 9 ++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/rh/__init__.py b/rh/__init__.py index 91a106c..2b1676e 100644 --- a/rh/__init__.py +++ b/rh/__init__.py @@ -14,8 +14,14 @@ """Common repohook objects/constants.""" -import collections +from typing import NamedTuple -# An object representing the git project that we're testing currently. -Project = collections.namedtuple('Project', ['name', 'dir']) +class Project(NamedTuple): + """The git project that we're testing currently.""" + + # The name of the project. + name: str + + # Absolute path to the project checkout. + dir: str diff --git a/rh/hooks.py b/rh/hooks.py index 47c3adb..c3e6e79 100644 --- a/rh/hooks.py +++ b/rh/hooks.py @@ -14,13 +14,13 @@ """Functions that implement the actual checks.""" -import collections import fnmatch import json import os import platform import re import sys +from typing import Callable, NamedTuple _path = os.path.realpath(__file__ + '/../..') if sys.path[0] != _path: @@ -243,8 +243,11 @@ class HookOptions(object): return self.expand_vars([tool_path])[0] -# A callable hook. -CallableHook = collections.namedtuple('CallableHook', ('name', 'hook', 'scope')) +class CallableHook(NamedTuple): + """A callable hook.""" + name: str + hook: Callable + scope: ExclusionScope def _run(cmd, **kwargs): -- cgit v1.2.3