Skip to content

Commit ec57802

Browse files
anakin87davidsbatista
authored andcommitted
chore!: github - drop Python 3.9 and use X|Y typing (#2705)
1 parent 1d0fbd6 commit ec57802

13 files changed

Lines changed: 76 additions & 75 deletions

File tree

integrations/github/pyproject.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,22 @@ name = "github-haystack"
77
dynamic = ["version"]
88
description = 'Haystack components for interacting with GitHub repositories'
99
readme = "README.md"
10-
requires-python = ">=3.9"
10+
requires-python = ">=3.10"
1111
license = "Apache-2.0"
1212
keywords = []
1313
authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
1414
classifiers = [
1515
"License :: OSI Approved :: Apache Software License",
1616
"Development Status :: 4 - Beta",
1717
"Programming Language :: Python",
18-
"Programming Language :: Python :: 3.9",
1918
"Programming Language :: Python :: 3.10",
2019
"Programming Language :: Python :: 3.11",
2120
"Programming Language :: Python :: 3.12",
2221
"Programming Language :: Python :: 3.13",
2322
"Programming Language :: Python :: Implementation :: CPython",
2423
"Programming Language :: Python :: Implementation :: PyPy",
2524
]
26-
dependencies = ["haystack-ai>=2.12.0"]
25+
dependencies = ["haystack-ai>=2.22.0"]
2726

2827
[project.urls]
2928
Source = "https://github.com/deepset-ai/haystack-core-integrations/github"
@@ -77,7 +76,6 @@ check_untyped_defs = true
7776
disallow_incomplete_defs = true
7877

7978
[tool.ruff]
80-
target-version = "py39"
8179
line-length = 120
8280

8381
[tool.ruff.lint]
@@ -124,10 +122,6 @@ ignore = [
124122
"B008",
125123
"S101",
126124
]
127-
unfixable = [
128-
# Don't touch unused imports
129-
"F401",
130-
]
131125

132126
[tool.ruff.lint.isort]
133127
known-first-party = ["haystack_integrations"]

integrations/github/src/haystack_integrations/components/connectors/github/file_editor.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44
from base64 import b64decode, b64encode
55
from enum import Enum
6-
from typing import Any, Optional, Union
6+
from typing import Any
77

88
import requests
99
from haystack import component, default_from_dict, default_to_dict, logging
@@ -79,7 +79,7 @@ def __init__(
7979
self,
8080
*,
8181
github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
82-
repo: Optional[str] = None,
82+
repo: str | None = None,
8383
branch: str = "main",
8484
raise_on_failure: bool = True,
8585
):
@@ -145,7 +145,7 @@ def _update_file(self, owner: str, repo: str, path: str, content: str, message:
145145
def _check_last_commit(self, owner: str, repo: str, branch: str) -> bool:
146146
"""Check if last commit was made by the current token user."""
147147
url = f"https://api.github.com/repos/{owner}/{repo}/commits"
148-
params: dict[str, Union[str, int]] = {"per_page": 1, "sha": branch}
148+
params: dict[str, str | int] = {"per_page": 1, "sha": branch}
149149
response = requests.get(url, headers=self._get_request_headers(), params=params, timeout=10)
150150
response.raise_for_status()
151151
last_commit = response.json()[0]
@@ -191,7 +191,7 @@ def _undo_changes(self, owner: str, repo: str, payload: dict[str, Any], branch:
191191
commits_url = f"https://api.github.com/repos/{owner}/{repo}/commits"
192192

193193
# Get the previous commit SHA
194-
params: dict[str, Union[str, int]] = {"per_page": 2, "sha": branch}
194+
params: dict[str, str | int] = {"per_page": 2, "sha": branch}
195195
commits = requests.get(commits_url, headers=self._get_request_headers(), params=params, timeout=10).json()
196196
previous_sha = commits[1]["sha"]
197197

@@ -244,10 +244,10 @@ def _delete_file(self, owner: str, repo: str, payload: dict[str, str], branch: s
244244
@component.output_types(result=str)
245245
def run(
246246
self,
247-
command: Union[Command, str],
247+
command: Command | str,
248248
payload: dict[str, Any],
249-
repo: Optional[str] = None,
250-
branch: Optional[str] = None,
249+
repo: str | None = None,
250+
branch: str | None = None,
251251
) -> dict[str, str]:
252252
"""
253253
Process GitHub file operations.

integrations/github/src/haystack_integrations/components/connectors/github/issue_viewer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44
import re
5-
from typing import Any, Optional
5+
from typing import Any
66

77
import requests
88
from haystack import Document, component, default_from_dict, default_to_dict, logging
@@ -37,7 +37,7 @@ class GitHubIssueViewer:
3737
def __init__(
3838
self,
3939
*,
40-
github_token: Optional[Secret] = None,
40+
github_token: Secret | None = None,
4141
raise_on_failure: bool = True,
4242
retry_attempts: int = 2,
4343
):

integrations/github/src/haystack_integrations/components/connectors/github/pr_creator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44
import re
5-
from typing import Any, Optional
5+
from typing import Any
66

77
import requests
88
from haystack import component, default_from_dict, default_to_dict, logging
@@ -102,7 +102,7 @@ def _check_fork_exists(self, repo: str, fork_owner: str) -> bool:
102102
except requests.RequestException:
103103
return False
104104

105-
def _create_fork(self, owner: str, repo: str) -> Optional[str]:
105+
def _create_fork(self, owner: str, repo: str) -> str | None:
106106
"""Create a fork of the repository."""
107107
url = f"https://api.github.com/repos/{owner}/{repo}/forks"
108108
try:

integrations/github/src/haystack_integrations/components/connectors/github/repo_forker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44
import re
55
import time
6-
from typing import Any, Optional
6+
from typing import Any
77

88
import requests
99
from haystack import component, default_from_dict, default_to_dict, logging
@@ -137,7 +137,7 @@ def _get_authenticated_user(self) -> str:
137137
response.raise_for_status()
138138
return response.json()["login"]
139139

140-
def _get_existing_repository(self, repo_name: str) -> Optional[str]:
140+
def _get_existing_repository(self, repo_name: str) -> str | None:
141141
"""
142142
Check if a repository with the given name already exists in the authenticated user's account.
143143

integrations/github/src/haystack_integrations/components/connectors/github/repo_viewer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44
import base64
55
from dataclasses import dataclass
6-
from typing import Any, Optional
6+
from typing import Any
77

88
import requests
99
from haystack import Document, component, default_from_dict, default_to_dict, logging
@@ -21,7 +21,7 @@ class GitHubItem:
2121
path: str
2222
size: int
2323
url: str
24-
content: Optional[str] = None
24+
content: str | None = None
2525

2626

2727
@component
@@ -71,10 +71,10 @@ class GitHubRepoViewer:
7171
def __init__(
7272
self,
7373
*,
74-
github_token: Optional[Secret] = None,
74+
github_token: Secret | None = None,
7575
raise_on_failure: bool = True,
7676
max_file_size: int = 1_000_000, # 1MB default limit
77-
repo: Optional[str] = None,
77+
repo: str | None = None,
7878
branch: str = "main",
7979
):
8080
"""
@@ -207,7 +207,7 @@ def _create_error_document(self, error: Exception, path: str) -> Document:
207207
)
208208

209209
@component.output_types(documents=list[Document])
210-
def run(self, path: str, repo: Optional[str] = None, branch: Optional[str] = None) -> dict[str, list[Document]]:
210+
def run(self, path: str, repo: str | None = None, branch: str | None = None) -> dict[str, list[Document]]:
211211
"""
212212
Process a GitHub repository path and return documents.
213213

integrations/github/src/haystack_integrations/tools/github/file_editor_tool.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Any, Callable, Optional, Union
4+
from collections.abc import Callable
5+
from typing import Any
56

67
from haystack.core.serialization import generate_qualified_class_name
78
from haystack.tools import ComponentTool
@@ -20,16 +21,16 @@ class GitHubFileEditorTool(ComponentTool):
2021
def __init__(
2122
self,
2223
*,
23-
name: Optional[str] = "file_editor",
24-
description: Optional[str] = FILE_EDITOR_PROMPT,
25-
parameters: Optional[dict[str, Any]] = FILE_EDITOR_SCHEMA,
24+
name: str | None = "file_editor",
25+
description: str | None = FILE_EDITOR_PROMPT,
26+
parameters: dict[str, Any] | None = FILE_EDITOR_SCHEMA,
2627
github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
27-
repo: Optional[str] = None,
28+
repo: str | None = None,
2829
branch: str = "main",
2930
raise_on_failure: bool = True,
30-
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None,
31-
inputs_from_state: Optional[dict[str, str]] = None,
32-
outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None,
31+
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
32+
inputs_from_state: dict[str, str] | None = None,
33+
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None,
3334
):
3435
"""
3536
Initialize the GitHub file editor tool.

integrations/github/src/haystack_integrations/tools/github/issue_commenter_tool.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Any, Callable, Optional, Union
4+
from collections.abc import Callable
5+
from typing import Any
56

67
from haystack.core.serialization import generate_qualified_class_name
78
from haystack.tools import ComponentTool
@@ -20,15 +21,15 @@ class GitHubIssueCommenterTool(ComponentTool):
2021
def __init__(
2122
self,
2223
*,
23-
name: Optional[str] = "issue_commenter",
24-
description: Optional[str] = ISSUE_COMMENTER_PROMPT,
25-
parameters: Optional[dict[str, Any]] = ISSUE_COMMENTER_SCHEMA,
24+
name: str | None = "issue_commenter",
25+
description: str | None = ISSUE_COMMENTER_PROMPT,
26+
parameters: dict[str, Any] | None = ISSUE_COMMENTER_SCHEMA,
2627
github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
2728
raise_on_failure: bool = True,
2829
retry_attempts: int = 2,
29-
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None,
30-
inputs_from_state: Optional[dict[str, str]] = None,
31-
outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None,
30+
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
31+
inputs_from_state: dict[str, str] | None = None,
32+
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None,
3233
):
3334
"""
3435
Initialize the GitHub issue commenter tool.

integrations/github/src/haystack_integrations/tools/github/issue_viewer_tool.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Any, Callable, Optional, Union
4+
from collections.abc import Callable
5+
from typing import Any
56

67
from haystack.core.serialization import generate_qualified_class_name
78
from haystack.tools import ComponentTool
@@ -20,15 +21,15 @@ class GitHubIssueViewerTool(ComponentTool):
2021
def __init__(
2122
self,
2223
*,
23-
name: Optional[str] = "issue_viewer",
24-
description: Optional[str] = ISSUE_VIEWER_PROMPT,
25-
parameters: Optional[dict[str, Any]] = ISSUE_VIEWER_SCHEMA,
26-
github_token: Optional[Secret] = None,
24+
name: str | None = "issue_viewer",
25+
description: str | None = ISSUE_VIEWER_PROMPT,
26+
parameters: dict[str, Any] | None = ISSUE_VIEWER_SCHEMA,
27+
github_token: Secret | None = None,
2728
raise_on_failure: bool = True,
2829
retry_attempts: int = 2,
29-
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None,
30-
inputs_from_state: Optional[dict[str, str]] = None,
31-
outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None,
30+
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
31+
inputs_from_state: dict[str, str] | None = None,
32+
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None,
3233
):
3334
"""
3435
Initialize the GitHub issue viewer tool.

integrations/github/src/haystack_integrations/tools/github/pr_creator_tool.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
22
#
33
# SPDX-License-Identifier: Apache-2.0
4-
from typing import Any, Callable, Optional, Union
4+
from collections.abc import Callable
5+
from typing import Any
56

67
from haystack.core.serialization import generate_qualified_class_name
78
from haystack.tools import ComponentTool
@@ -20,14 +21,14 @@ class GitHubPRCreatorTool(ComponentTool):
2021
def __init__(
2122
self,
2223
*,
23-
name: Optional[str] = "pr_creator",
24-
description: Optional[str] = PR_CREATOR_PROMPT,
25-
parameters: Optional[dict[str, Any]] = PR_CREATOR_SCHEMA,
24+
name: str | None = "pr_creator",
25+
description: str | None = PR_CREATOR_PROMPT,
26+
parameters: dict[str, Any] | None = PR_CREATOR_SCHEMA,
2627
github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
2728
raise_on_failure: bool = True,
28-
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None,
29-
inputs_from_state: Optional[dict[str, str]] = None,
30-
outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None,
29+
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
30+
inputs_from_state: dict[str, str] | None = None,
31+
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None,
3132
):
3233
"""
3334
Initialize the GitHub PR creator tool.

0 commit comments

Comments
 (0)