88from contextlib import contextmanager
99from pathlib import Path , PurePosixPath
1010from tempfile import NamedTemporaryFile , TemporaryDirectory , mkdtemp
11- from typing import TYPE_CHECKING , Any , BinaryIO , Optional , Type
11+ from typing import TYPE_CHECKING , Any , BinaryIO , Generator , Optional , Type
1212
1313from fs import ResourceType
1414from fs .base import FS
4040
4141
4242@contextmanager
43- def synapse_errors (path ) :
43+ def synapse_errors (path : str ) -> Generator :
4444 """A context manager for mapping ``synapseclient`` errors to ``fs`` errors."""
4545 try :
4646 yield
@@ -116,12 +116,13 @@ def synapse(self) -> Synapse:
116116 Synapse: Authenticated Synapse client
117117 """
118118 if not hasattr (self ._local , "synapse" ):
119- # Override cache with temporary directory to avoid unwanted side effects
119+ # Override cache with temporary directory
120120 self .synapse_args ["cache_root_dir" ] = mkdtemp ()
121121 synapse = Synapse (** self .synapse_args )
122122 synapse .login (authToken = self .auth_token )
123123 self ._local .synapse = synapse
124- # Clear the Synapse cache to ensure up-to-date
124+ # Clear the Synapse cache to avoid unwanted side effects. More info here:
125+ # https://github.com/Sage-Bionetworks-Workflows/py-dcqc/pull/3#discussion_r1068443214
125126 self ._local .synapse .cache .purge (after_date = 0 )
126127 return self ._local .synapse
127128
@@ -237,7 +238,11 @@ def _path_to_synapse_id(
237238
238239 return current_entity
239240
240- def _synapse_id_to_entity (self , synapse_id : str , download_file = False ) -> Entity :
241+ def _synapse_id_to_entity (
242+ self ,
243+ synapse_id : str ,
244+ download_file : bool = False ,
245+ ) -> Entity :
241246 """Retrieve and validate (meta)data for a Synapse entity
242247
243248 Args:
@@ -261,7 +266,7 @@ def _synapse_id_to_entity(self, synapse_id: str, download_file=False) -> Entity:
261266 raise ResourceInvalid (message )
262267 return entity
263268
264- def _path_to_entity (self , path : str , download_file = False ) -> Entity :
269+ def _path_to_entity (self , path : str , download_file : bool = False ) -> Entity :
265270 """Perform the validation and retrieval steps for a Synapse entity.
266271
267272 Arguments:
@@ -534,7 +539,7 @@ def openbin(
534539 temp_dir = TemporaryDirectory ()
535540 temp_path = temp_dir .name
536541
537- def on_close (remote_file ) :
542+ def on_close (remote_file : RemoteFile ) -> None :
538543 """Called when the S3 file closes, to upload data."""
539544 # If the file is empty, add a null byte to bypass
540545 # Synapse restriction on empty files
@@ -579,7 +584,7 @@ def on_close(remote_file):
579584
580585 return RemoteFile (target_file , file_name , mode_obj , on_close )
581586
582- def remove (self , path : str ):
587+ def remove (self , path : str ) -> None :
583588 """Remove a file from the filesystem.
584589
585590 Arguments:
@@ -600,7 +605,7 @@ def remove(self, path: str):
600605
601606 self .synapse .delete (entity )
602607
603- def removedir (self , path : str ):
608+ def removedir (self , path : str ) -> None :
604609 """Remove a directory from the filesystem.
605610
606611 Arguments:
@@ -639,7 +644,7 @@ def removedir(self, path: str):
639644
640645 self .synapse .delete (entity )
641646
642- def setinfo (self , path : str , info : RawInfo ):
647+ def setinfo (self , path : str , info : RawInfo ) -> None :
643648 """Set info on a resource.
644649
645650 This method is the complement to `~fs.base.FS.getinfo`
0 commit comments