changeset 50638:8fc10bfd9887

store: declare a `files` method on BaseStoreEntry This will help pytype to type check. We have to move `StoreFile` earlier in the file to use it in the type declaration.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 29 May 2023 11:42:16 +0200
parents 32837c7e2e4b
children 5e60abf811f3
files mercurial/store.py
diffstat 1 files changed, 23 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/store.py	Sun May 28 05:23:46 2023 +0200
+++ b/mercurial/store.py	Mon May 29 11:42:16 2023 +0200
@@ -10,7 +10,7 @@
 import os
 import re
 import stat
-from typing import Generator
+from typing import Generator, List
 
 from .i18n import _
 from .pycompat import getattr
@@ -459,12 +459,32 @@
 FILETYPE_OTHER = FILEFLAGS_OTHER
 
 
+@attr.s(slots=True)
+class StoreFile:
+    """a file matching a store entry"""
+
+    unencoded_path = attr.ib()
+    _file_size = attr.ib(default=None)
+    is_volatile = attr.ib(default=False)
+
+    def file_size(self, vfs):
+        if self._file_size is None:
+            try:
+                self._file_size = vfs.stat(self.unencoded_path).st_size
+            except FileNotFoundError:
+                self._file_size = 0
+        return self._file_size
+
+
 @attr.s(slots=True, init=False)
 class BaseStoreEntry:
     """An entry in the store
 
     This is returned by `store.walk` and represent some data in the store."""
 
+    def files(self) -> List[StoreFile]:
+        raise NotImplementedError
+
 
 @attr.s(slots=True, init=False)
 class SimpleStoreEntry(BaseStoreEntry):
@@ -489,7 +509,7 @@
         self._file_size = file_size
         self._files = None
 
-    def files(self):
+    def files(self) -> List[StoreFile]:
         if self._files is None:
             self._files = [
                 StoreFile(
@@ -544,7 +564,7 @@
         """unencoded path of the main revlog file"""
         return self._path_prefix + b'.i'
 
-    def files(self):
+    def files(self) -> List[StoreFile]:
         if self._files is None:
             self._files = []
             for ext in sorted(self._details, key=_ext_key):
@@ -569,23 +589,6 @@
             return filelog.filelog(repo.svfs, self.target_id)
 
 
-@attr.s(slots=True)
-class StoreFile:
-    """a file matching an entry"""
-
-    unencoded_path = attr.ib()
-    _file_size = attr.ib(default=None)
-    is_volatile = attr.ib(default=False)
-
-    def file_size(self, vfs):
-        if self._file_size is None:
-            try:
-                self._file_size = vfs.stat(self.unencoded_path).st_size
-            except FileNotFoundError:
-                self._file_size = 0
-        return self._file_size
-
-
 def _gather_revlog(files_data):
     """group files per revlog prefix