Add futures for type hints (#506)
Co-authored-by: UltralyticsAssistant <[email protected]>
This commit is contained in:
co-authored by
UltralyticsAssistant
parent
ee08f1071a
commit
197e42d4a3
@@ -1,8 +1,9 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
from datetime import datetime
|
||||
from typing import Dict, List
|
||||
|
||||
from .utils import GITHUB_API_URL, Action
|
||||
|
||||
@@ -18,7 +19,7 @@ def get_pr_branch(event) -> str:
|
||||
return pr_data.get("head", {}).get("ref", "main")
|
||||
|
||||
|
||||
def trigger_and_get_workflow_info(event, branch: str) -> List[Dict]:
|
||||
def trigger_and_get_workflow_info(event, branch: str) -> list[dict]:
|
||||
"""Triggers workflows and returns their information."""
|
||||
repo = event.repository
|
||||
results = []
|
||||
@@ -56,7 +57,7 @@ def trigger_and_get_workflow_info(event, branch: str) -> List[Dict]:
|
||||
return results
|
||||
|
||||
|
||||
def update_comment(event, comment_body: str, triggered_actions: List[Dict], branch: str) -> bool:
|
||||
def update_comment(event, comment_body: str, triggered_actions: list[dict], branch: str) -> bool:
|
||||
"""Updates the comment with workflow information."""
|
||||
if not triggered_actions:
|
||||
return False
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from typing import Dict, List, Tuple
|
||||
|
||||
from .utils import GITHUB_API_URL, Action, get_completion, remove_html_comments
|
||||
|
||||
@@ -9,7 +10,7 @@ from .utils import GITHUB_API_URL, Action, get_completion, remove_html_comments
|
||||
BLOCK_USER = os.getenv("BLOCK_USER", "false").lower() == "true"
|
||||
|
||||
|
||||
def get_event_content(event) -> Tuple[int, str, str, str, str, str, str]:
|
||||
def get_event_content(event) -> tuple[int, str, str, str, str, str, str]:
|
||||
"""Extracts key information from GitHub event data for issues, pull requests, or discussions."""
|
||||
data = event.event_data
|
||||
name = event.event_name
|
||||
@@ -108,8 +109,8 @@ def block_user(event, username: str):
|
||||
|
||||
|
||||
def get_relevant_labels(
|
||||
issue_type: str, title: str, body: str, available_labels: Dict, current_labels: List
|
||||
) -> List[str]:
|
||||
issue_type: str, title: str, body: str, available_labels: dict, current_labels: list
|
||||
) -> list[str]:
|
||||
"""Determines relevant labels for GitHub issues/PRs using OpenAI, considering title, body, and existing labels."""
|
||||
# Remove mutually exclusive labels like both 'bug' and 'question' or inappropriate labels like 'help wanted'
|
||||
for label in {
|
||||
@@ -178,7 +179,7 @@ YOUR RESPONSE (label names only):
|
||||
]
|
||||
|
||||
|
||||
def get_label_ids(event, labels: List[str]) -> List[str]:
|
||||
def get_label_ids(event, labels: list[str]) -> list[str]:
|
||||
"""Retrieves GitHub label IDs for a list of label names using the GraphQL API."""
|
||||
query = """
|
||||
query($owner: String!, $name: String!) {
|
||||
@@ -202,7 +203,7 @@ query($owner: String!, $name: String!) {
|
||||
return []
|
||||
|
||||
|
||||
def apply_labels(event, number: int, node_id: str, labels: List[str], issue_type: str):
|
||||
def apply_labels(event, number: int, node_id: str, labels: list[str], issue_type: str):
|
||||
"""Applies specified labels to a GitHub issue, pull request, or discussion using the appropriate API."""
|
||||
if "Alert" in labels:
|
||||
create_alert_label(event)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
|
||||
from .utils import GITHUB_API_URL, GITHUB_GRAPHQL_URL, Action, get_completion
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import re
|
||||
import shutil
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
import requests
|
||||
|
||||
@@ -96,7 +97,7 @@ class Action:
|
||||
"""Checks if the repository is public using event data or GitHub API if needed."""
|
||||
return self.event_data.get("repository", {}).get("private")
|
||||
|
||||
def get_username(self) -> Union[str, None]:
|
||||
def get_username(self) -> str | None:
|
||||
"""Gets username associated with the GitHub token."""
|
||||
response = self.post(GITHUB_GRAPHQL_URL, json={"query": "query { viewer { login } }"})
|
||||
if response.status_code == 200:
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import time
|
||||
from typing import Dict, List
|
||||
|
||||
import requests
|
||||
|
||||
@@ -34,9 +35,9 @@ def remove_outer_codeblocks(string):
|
||||
|
||||
|
||||
def get_completion(
|
||||
messages: List[Dict[str, str]],
|
||||
messages: list[dict[str, str]],
|
||||
check_links: bool = True,
|
||||
remove: List[str] = (" @giscus[bot]",), # strings to remove from response
|
||||
remove: list[str] = (" @giscus[bot]",), # strings to remove from response
|
||||
temperature: float = 1.0, # note GPT-5 requires temperature=1.0
|
||||
reasoning_effort: str = None, # reasoning effort for GPT-5 models: minimal, low, medium, high
|
||||
) -> str:
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
# from actions.utils.version_utils import check_pypi_version
|
||||
# check_pypi_version()
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
# tests/test_update_file_headers.py
|
||||
"""Tests for the file headers update functionality."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
||||
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import mock_open, patch
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
# Continuous Integration (CI) GitHub Actions tests
|
||||
|
||||
|
||||
import pytest
|
||||
|
||||
from actions.utils.common_utils import check_links_in_string, is_url
|
||||
|
||||
Reference in New Issue
Block a user