Skip to content

Commit e0b03e5

Browse files
refactor: ♻️ update type hints to use built-in types for future types (#159)
Signed-off-by: Onuralp SEZER <[email protected]> Signed-off-by: Glenn Jocher <[email protected]> Co-authored-by: Glenn Jocher <[email protected]>
1 parent 916e8cf commit e0b03e5

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

plugin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
22

3-
__version__ = "0.1.29"
3+
__version__ = "0.1.30"
44

55
from .main import MetaPlugin
66

plugin/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
22

3+
from __future__ import annotations
4+
35
import json
46
import re
57
import subprocess
68
from datetime import datetime, timedelta
79
from pathlib import Path
810
from subprocess import check_output
9-
from typing import Any, Dict, List
11+
from typing import Any
1012

1113
from bs4 import BeautifulSoup
1214
from mkdocs.config import config_options
@@ -70,7 +72,7 @@ def __init__(self):
7072
except (subprocess.CalledProcessError, FileNotFoundError):
7173
self.git_available = False
7274

73-
def get_git_info(self, file_path: str) -> Dict[str, Any]:
75+
def get_git_info(self, file_path: str) -> dict[str, Any]:
7476
"""Retrieve git information including creation/modified dates and optional authors."""
7577
file_path = str(Path(file_path).resolve())
7678
git_info = {"creation_date": DEFAULT_CREATION_DATE, "last_modified_date": DEFAULT_MODIFIED_DATE}
@@ -172,7 +174,7 @@ def insert_content(soup: BeautifulSoup, content_to_insert) -> None:
172174
md_typeset.append(content_to_insert)
173175

174176
@staticmethod
175-
def parse_faq(soup: BeautifulSoup) -> List[Dict[str, Any]]:
177+
def parse_faq(soup: BeautifulSoup) -> list[dict[str, Any]]:
176178
"""
177179
Parse the FAQ questions and answers from the HTML page content.
178180

plugin/utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
22

3+
from __future__ import annotations
4+
35
import contextlib
46
import re
57
import subprocess
68
from collections import Counter
79
from datetime import datetime
810
from pathlib import Path
9-
from typing import Dict, List, Optional, Tuple
1011

1112
import requests
1213
import yaml # YAML is used for its readability and consistency with MkDocs ecosystem
@@ -16,7 +17,7 @@
1617
DEFAULT_AVATAR = requests.head("https://github.com/github.png", allow_redirects=True).url
1718

1819

19-
def calculate_time_difference(date_string: str) -> Tuple[str, str]:
20+
def calculate_time_difference(date_string: str) -> tuple[str, str]:
2021
"""
2122
Calculate the time difference between a given date and the current date in a human-readable format.
2223
@@ -48,7 +49,7 @@ def calculate_time_difference(date_string: str) -> Tuple[str, str]:
4849
return difference, pretty_date
4950

5051

51-
def get_youtube_video_ids(soup: BeautifulSoup) -> List[str]:
52+
def get_youtube_video_ids(soup: BeautifulSoup) -> list[str]:
5253
"""
5354
Extract YouTube video IDs from iframe elements present in the provided BeautifulSoup object.
5455
@@ -83,8 +84,8 @@ def get_youtube_video_ids(soup: BeautifulSoup) -> List[str]:
8384

8485

8586
def get_github_username_from_email(
86-
email: str, cache: Dict, file_path: str = "", verbose: bool = True
87-
) -> Tuple[Optional[str], Optional[str]]:
87+
email: str, cache: dict, file_path: str = "", verbose: bool = True
88+
) -> tuple[str | None, str | None]:
8889
"""
8990
Retrieve the GitHub username and avatar URL associated with the given email address.
9091
@@ -137,7 +138,7 @@ def get_github_username_from_email(
137138
return None, None
138139

139140

140-
def get_github_usernames_from_file(file_path: str, default_user: Optional[str] = None) -> Dict[str, Dict[str, any]]:
141+
def get_github_usernames_from_file(file_path: str, default_user: str | None = None) -> dict[str, dict[str, any]]:
141142
"""
142143
Fetch GitHub usernames associated with a file using Git Log and Git Blame commands.
143144

0 commit comments

Comments
 (0)