From b6f5e30b53c8331b19a40a3c086af8ffa3a7e222 Mon Sep 17 00:00:00 2001
From: Valentin Lorentz <vlorentz@softwareheritage.org>
Date: Thu, 16 Sep 2021 14:09:15 +0200
Subject: [PATCH] HashableObject: Add type annotation for 'id' attribute

This class is a mixin that only works with classes that define
this attribute, so it makes sense to declare it.

It also allows generic functions (that take a HashableObject
parameter) to access it without 'type: ignore'.
---
 swh/model/model.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/swh/model/model.py b/swh/model/model.py
index 39331793..ee1be689 100644
--- a/swh/model/model.py
+++ b/swh/model/model.py
@@ -121,6 +121,8 @@ class HashableObject(metaclass=ABCMeta):
 
     __slots__ = ()
 
+    id: Sha1Git
+
     @abstractmethod
     def compute_hash(self) -> bytes:
         """Derived model classes must implement this to compute
@@ -137,7 +139,7 @@ class HashableObject(metaclass=ABCMeta):
             object.__setattr__(self, "id", obj_id)
 
     def unique_key(self) -> KeyType:
-        return self.id  # type: ignore
+        return self.id
 
 
 @attr.s(frozen=True, slots=True)
-- 
GitLab