Skip to content

Commit 898571a

Browse files
anakin87sjrl
authored andcommitted
unpin ruff and update code (#9040)
1 parent 7c3b05d commit 898571a

23 files changed

+33
-33
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
args: [--markdown-linebreak-ext=md]
1818

1919
- repo: https://github.com/astral-sh/ruff-pre-commit
20-
rev: v0.9.2
20+
rev: v0.11.0
2121
hooks:
2222
- id: ruff
2323
- id: ruff-format

haystack/components/converters/output_adapter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(
9595
input_types.update(route_input_names)
9696

9797
# the env is not needed, discarded automatically
98-
component.set_input_types(self, **{var: Any for var in input_types})
98+
component.set_input_types(self, **dict.fromkeys(input_types, Any))
9999
component.set_output_types(self, **{"output": output_type})
100100
self.output_type = output_type
101101

haystack/components/embedders/azure_document_embedder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def __init__( # noqa: PLR0913 (too-many-arguments) # pylint: disable=too-many-p
124124
self.progress_bar = progress_bar
125125
self.meta_fields_to_embed = meta_fields_to_embed or []
126126
self.embedding_separator = embedding_separator
127-
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", 30.0))
128-
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", 5))
127+
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", "30.0"))
128+
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", "5"))
129129
self.default_headers = default_headers or {}
130130

131131
self._client = AzureOpenAI(

haystack/components/embedders/azure_text_embedder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ def __init__( # pylint: disable=too-many-positional-arguments
104104
self.azure_deployment = azure_deployment
105105
self.dimensions = dimensions
106106
self.organization = organization
107-
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", 30.0))
108-
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", 5))
107+
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", "30.0"))
108+
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", "5"))
109109
self.prefix = prefix
110110
self.suffix = suffix
111111
self.default_headers = default_headers or {}

haystack/components/embedders/openai_document_embedder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ def __init__( # pylint: disable=too-many-positional-arguments
108108
self.embedding_separator = embedding_separator
109109

110110
if timeout is None:
111-
timeout = float(os.environ.get("OPENAI_TIMEOUT", 30.0))
111+
timeout = float(os.environ.get("OPENAI_TIMEOUT", "30.0"))
112112
if max_retries is None:
113-
max_retries = int(os.environ.get("OPENAI_MAX_RETRIES", 5))
113+
max_retries = int(os.environ.get("OPENAI_MAX_RETRIES", "5"))
114114

115115
self.client = OpenAI(
116116
api_key=api_key.resolve_value(),

haystack/components/embedders/openai_text_embedder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def __init__( # pylint: disable=too-many-positional-arguments
9090
self.api_key = api_key
9191

9292
if timeout is None:
93-
timeout = float(os.environ.get("OPENAI_TIMEOUT", 30.0))
93+
timeout = float(os.environ.get("OPENAI_TIMEOUT", "30.0"))
9494
if max_retries is None:
95-
max_retries = int(os.environ.get("OPENAI_MAX_RETRIES", 5))
95+
max_retries = int(os.environ.get("OPENAI_MAX_RETRIES", "5"))
9696

9797
self.client = OpenAI(
9898
api_key=api_key.resolve_value(),

haystack/components/generators/azure.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def __init__( # pylint: disable=too-many-positional-arguments
136136
self.azure_deployment = azure_deployment
137137
self.organization = organization
138138
self.model: str = azure_deployment or "gpt-4o-mini"
139-
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", 30.0))
140-
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", 5))
139+
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", "30.0"))
140+
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", "5"))
141141
self.default_headers = default_headers or {}
142142

143143
self.client = AzureOpenAI(

haystack/components/generators/chat/azure.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def __init__( # pylint: disable=too-many-positional-arguments
146146
self.azure_deployment = azure_deployment
147147
self.organization = organization
148148
self.model = azure_deployment or "gpt-4o-mini"
149-
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", 30.0))
150-
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", 5))
149+
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", "30.0"))
150+
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", "5"))
151151
self.default_headers = default_headers or {}
152152

153153
_check_duplicate_tool_names(tools)

haystack/components/generators/chat/openai.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def __init__( # pylint: disable=too-many-positional-arguments
146146
_check_duplicate_tool_names(tools)
147147

148148
if timeout is None:
149-
timeout = float(os.environ.get("OPENAI_TIMEOUT", 30.0))
149+
timeout = float(os.environ.get("OPENAI_TIMEOUT", "30.0"))
150150
if max_retries is None:
151-
max_retries = int(os.environ.get("OPENAI_MAX_RETRIES", 5))
151+
max_retries = int(os.environ.get("OPENAI_MAX_RETRIES", "5"))
152152

153153
client_args: Dict[str, Any] = {
154154
"api_key": api_key.resolve_value(),

haystack/components/generators/openai.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ def __init__( # pylint: disable=too-many-positional-arguments
112112
self.organization = organization
113113

114114
if timeout is None:
115-
timeout = float(os.environ.get("OPENAI_TIMEOUT", 30.0))
115+
timeout = float(os.environ.get("OPENAI_TIMEOUT", "30.0"))
116116
if max_retries is None:
117-
max_retries = int(os.environ.get("OPENAI_MAX_RETRIES", 5))
117+
max_retries = int(os.environ.get("OPENAI_MAX_RETRIES", "5"))
118118

119119
self.client = OpenAI(
120120
api_key=api_key.resolve_value(),

haystack/components/generators/openai_dalle.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def __init__( # pylint: disable=too-many-positional-arguments
7171
self.api_base_url = api_base_url
7272
self.organization = organization
7373

74-
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", 30.0))
75-
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", 5))
74+
self.timeout = timeout or float(os.environ.get("OPENAI_TIMEOUT", "30.0"))
75+
self.max_retries = max_retries or int(os.environ.get("OPENAI_MAX_RETRIES", "5"))
7676

7777
self.client: Optional[OpenAI] = None
7878

haystack/components/routers/conditional_router.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def __init__( # pylint: disable=too-many-positional-arguments
225225
logger.warning(msg)
226226

227227
# add mandatory input types
228-
component.set_input_types(self, **{var: Any for var in mandatory_input_types})
228+
component.set_input_types(self, **dict.fromkeys(mandatory_input_types, Any))
229229

230230
# now add optional input types
231231
for optional_var_name in self.optional_variables:

haystack/components/routers/file_type_router.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(self, mime_types: List[str], additional_mimetypes: Optional[Dict[st
9696
component.set_output_types(
9797
self,
9898
unclassified=List[Union[str, Path, ByteStream]],
99-
**{mime_type: List[Union[str, Path, ByteStream]] for mime_type in mime_types},
99+
**dict.fromkeys(mime_types, List[Union[str, Path, ByteStream]]),
100100
)
101101
self.mime_types = mime_types
102102
self._additional_mimetypes = additional_mimetypes

haystack/components/routers/metadata_router.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(self, rules: Dict[str, Dict]):
8181
raise ValueError(
8282
"Invalid filter syntax. See https://docs.haystack.deepset.ai/docs/metadata-filtering for details."
8383
)
84-
component.set_output_types(self, unmatched=List[Document], **{edge: List[Document] for edge in rules})
84+
component.set_output_types(self, unmatched=List[Document], **dict.fromkeys(rules, List[Document]))
8585

8686
def run(self, documents: List[Document]):
8787
"""

haystack/components/routers/text_language_router.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, languages: Optional[List[str]] = None):
5959
if not languages:
6060
languages = ["en"]
6161
self.languages = languages
62-
component.set_output_types(self, unmatched=str, **{language: str for language in languages})
62+
component.set_output_types(self, unmatched=str, **dict.fromkeys(languages, str))
6363

6464
def run(self, text: str) -> Dict[str, str]:
6565
"""

haystack/components/routers/transformers_text_router.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def __init__( # pylint: disable=too-many-positional-arguments
116116
self.labels = list(config.label2id.keys())
117117
else:
118118
self.labels = labels
119-
component.set_output_types(self, **{label: str for label in self.labels})
119+
component.set_output_types(self, **dict.fromkeys(self.labels, str))
120120

121121
self.pipeline = None
122122

haystack/components/routers/zero_shot_text_router.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __init__( # pylint: disable=too-many-positional-arguments
128128
self.token = token
129129
self.labels = labels
130130
self.multi_label = multi_label
131-
component.set_output_types(self, **{label: str for label in labels})
131+
component.set_output_types(self, **dict.fromkeys(labels, str))
132132

133133
huggingface_pipeline_kwargs = resolve_hf_pipeline_kwargs(
134134
huggingface_pipeline_kwargs=huggingface_pipeline_kwargs or {},

haystack/core/pipeline/async_pipeline.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def process_results():
143143
# For quick lookup of downstream receivers
144144
ordered_names = sorted(self.graph.nodes.keys())
145145
cached_receivers = {n: self._find_receivers_from(n) for n in ordered_names}
146-
component_visits = {component_name: 0 for component_name in ordered_names}
146+
component_visits = dict.fromkeys(ordered_names, 0)
147147
cached_topological_sort = None
148148

149149
# We fill the queue once and raise if all components are BLOCKED

haystack/core/pipeline/pipeline.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def run( # noqa: PLR0915, PLR0912
202202
ordered_component_names = sorted(self.graph.nodes.keys())
203203

204204
# We track component visits to decide if a component can run.
205-
component_visits = {component_name: 0 for component_name in ordered_component_names}
205+
component_visits = dict.fromkeys(ordered_component_names, 0)
206206

207207
# We need to access a component's receivers multiple times during a pipeline run.
208208
# We store them here for easy access.

haystack/testing/factory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def init(self):
214214
def run(self, **kwargs): # pylint: disable=unused-argument
215215
if output is not None:
216216
return output
217-
return {name: None for name in output_types.keys()}
217+
return dict.fromkeys(output_types.keys())
218218

219219
def to_dict(self):
220220
return default_to_dict(self)

haystack/testing/sample_components/fstring.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, template: str, variables: Optional[List[str]] = None):
1818
self.variables = variables or []
1919
if "template" in self.variables:
2020
raise ValueError("The variable name 'template' is reserved and cannot be used.")
21-
component.set_input_types(self, **{variable: Any for variable in self.variables})
21+
component.set_input_types(self, **dict.fromkeys(self.variables, Any))
2222

2323
@component.output_types(string=str)
2424
def run(self, template: Optional[str] = None, **kwargs):

haystack/testing/sample_components/repeat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
class Repeat:
1212
def __init__(self, outputs: List[str]):
1313
self._outputs = outputs
14-
component.set_output_types(self, **{k: int for k in outputs})
14+
component.set_output_types(self, **dict.fromkeys(outputs, int))
1515

1616
def run(self, value: int):
1717
"""
1818
:param value: the value to repeat.
1919
"""
20-
return {val: value for val in self._outputs}
20+
return dict.fromkeys(self._outputs, value)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ dependencies = [
6464
installer = "uv"
6565
dependencies = [
6666
"pre-commit",
67-
"ruff<0.10.0",
67+
"ruff",
6868
"toml",
6969
"reno",
7070
# dulwich is a reno dependency, they pin it at >=0.15.0 so pip takes ton of time to resolve the dependency tree.

0 commit comments

Comments
 (0)