33# SPDX-License-Identifier: Apache-2.0
44
55import os
6+ from collections .abc import Callable
67from concurrent .futures import ThreadPoolExecutor
78from pathlib import Path
8- from typing import Any , Callable , Optional
9+ from typing import Any
910
1011from botocore .config import Config
1112from haystack import component , default_from_dict , default_to_dict , logging
@@ -29,20 +30,20 @@ class S3Downloader:
2930 def __init__ (
3031 self ,
3132 * ,
32- aws_access_key_id : Optional [ Secret ] = Secret .from_env_var ("AWS_ACCESS_KEY_ID" , strict = False ), # noqa: B008
33- aws_secret_access_key : Optional [ Secret ] = Secret .from_env_var ( # noqa: B008
33+ aws_access_key_id : Secret | None = Secret .from_env_var ("AWS_ACCESS_KEY_ID" , strict = False ), # noqa: B008
34+ aws_secret_access_key : Secret | None = Secret .from_env_var ( # noqa: B008
3435 "AWS_SECRET_ACCESS_KEY" , strict = False
3536 ),
36- aws_session_token : Optional [ Secret ] = Secret .from_env_var ("AWS_SESSION_TOKEN" , strict = False ), # noqa: B008
37- aws_region_name : Optional [ Secret ] = Secret .from_env_var ("AWS_DEFAULT_REGION" , strict = False ), # noqa: B008
38- aws_profile_name : Optional [ Secret ] = Secret .from_env_var ("AWS_PROFILE" , strict = False ), # noqa: B008
39- boto3_config : Optional [ dict [str , Any ]] = None ,
40- file_root_path : Optional [ str ] = None ,
41- file_extensions : Optional [ list [str ]] = None ,
37+ aws_session_token : Secret | None = Secret .from_env_var ("AWS_SESSION_TOKEN" , strict = False ), # noqa: B008
38+ aws_region_name : Secret | None = Secret .from_env_var ("AWS_DEFAULT_REGION" , strict = False ), # noqa: B008
39+ aws_profile_name : Secret | None = Secret .from_env_var ("AWS_PROFILE" , strict = False ), # noqa: B008
40+ boto3_config : dict [str , Any ] | None = None ,
41+ file_root_path : str | None = None ,
42+ file_extensions : list [str ] | None = None ,
4243 file_name_meta_key : str = "file_name" ,
4344 max_workers : int = 32 ,
4445 max_cache_size : int = 100 ,
45- s3_key_generation_function : Optional [ Callable [[Document ], str ]] = None ,
46+ s3_key_generation_function : Callable [[Document ], str ] | None = None ,
4647 ) -> None :
4748 """
4849 Initializes the `S3Downloader` with the provided parameters.
@@ -104,9 +105,9 @@ def __init__(
104105 self .file_name_meta_key = file_name_meta_key
105106 self .s3_key_generation_function = s3_key_generation_function
106107
107- self ._storage : Optional [ S3Storage ] = None
108+ self ._storage : S3Storage | None = None
108109
109- def resolve_secret (secret : Optional [ Secret ] ) -> Optional [ str ] :
110+ def resolve_secret (secret : Secret | None ) -> str | None :
110111 return secret .resolve_value () if secret else None
111112
112113 self ._session = get_aws_session (
@@ -169,7 +170,7 @@ def _filter_documents_by_extensions(self, documents: list[Document]) -> list[Doc
169170 if Path (doc .meta .get (self .file_name_meta_key , "" )).suffix .lower () in self .file_extensions
170171 ]
171172
172- def _download_file (self , document : Document ) -> Optional [ Document ] :
173+ def _download_file (self , document : Document ) -> Document | None :
173174 """
174175 Download a single file from AWS S3 Bucket to local filesystem.
175176
0 commit comments