44import json
55from abc import ABC , abstractmethod
66from pathlib import Path
7- from typing import Iterable , List , Optional , Type , TypeVar , Union , cast
7+ from typing import Iterable , List , Optional , Tuple , Type , TypeVar , Union , cast
88
99from .hashing import Hash , Hashed , HashedBytes , HashedComposite , HashResolver
1010from .rules import Rule
@@ -162,7 +162,7 @@ def from_path(
162162@HashedComposite .register_type (File )
163163class HashedFile (Hashed [File ]):
164164 def __init__ (self , file : File ):
165- self ._path = file . path
165+ self ._file = file
166166 if isinstance (file .content , bytes ):
167167 self ._content : Optional [HashedBytes ] = HashedBytes (file .content )
168168 self ._content_hash = self ._content .hashid
@@ -172,28 +172,26 @@ def __init__(self, file: File):
172172
173173 @property
174174 def spec (self ) -> bytes :
175- return json .dumps ([str (self ._path ), self ._content_hash ]).encode ()
175+ return json .dumps ([str (self ._file . path ), self ._content_hash ]).encode ()
176176
177177 @classmethod
178178 def from_spec (cls , spec : bytes , resolve : HashResolver ) -> 'HashedFile' :
179- path_str : str
180- content_hash : Hash
181- path_str , content_hash = json .loads (spec )
179+ path_str , content_hash = cast (Tuple [str , Hash ], json .loads (spec ))
182180 path = Path (path_str )
183181 fmngr = FileManager .active ()
184182 if fmngr :
185- return cls (File (path , content_hash ))
186- return cls (File (path , cast (HashedBytes , resolve (content_hash )).value ))
183+ file = File (path , content_hash )
184+ else :
185+ file = File (path , cast (HashedBytes , resolve (content_hash )).value )
186+ return cls (file )
187187
188188 @property
189189 def value (self ) -> File :
190- return File (
191- self ._path , self ._content .value if self ._content else self ._content_hash
192- )
190+ return self ._file
193191
194192 @property
195193 def label (self ) -> str :
196- return f'./{ self ._path } '
194+ return f'./{ self ._file . path } '
197195
198196 @property
199197 def components (self ) -> Iterable ['Hashed[object]' ]:
0 commit comments