]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
♻️ Move from `Optional[X]` to `Union[X, None]` for internal utils (#5124)
authorSebastián Ramírez <tiangolo@gmail.com>
Mon, 11 Jul 2022 19:30:41 +0000 (21:30 +0200)
committerGitHub <noreply@github.com>
Mon, 11 Jul 2022 19:30:41 +0000 (19:30 +0000)
.github/actions/comment-docs-preview-in-pr/app/main.py
.github/actions/notify-translations/app/main.py
.github/actions/people/app/main.py
.github/actions/watch-previews/app/main.py

index c9fb7cbbefac61a475467302784eb8fd4df086ec..68914fdb9a81895ff185dd01f69c757d292059c2 100644 (file)
@@ -1,7 +1,7 @@
 import logging
 import sys
 from pathlib import Path
-from typing import Optional
+from typing import Union
 
 import httpx
 from github import Github
@@ -14,7 +14,7 @@ github_api = "https://api.github.com"
 class Settings(BaseSettings):
     github_repository: str
     github_event_path: Path
-    github_event_name: Optional[str] = None
+    github_event_name: Union[str, None] = None
     input_token: SecretStr
     input_deploy_url: str
 
@@ -42,7 +42,7 @@ if __name__ == "__main__":
     except ValidationError as e:
         logging.error(f"Error parsing event file: {e.errors()}")
         sys.exit(0)
-    use_pr: Optional[PullRequest] = None
+    use_pr: Union[PullRequest, None] = None
     for pr in repo.get_pulls():
         if pr.head.sha == event.workflow_run.head_commit.id:
             use_pr = pr
index 823685e00b12219dde7bafdb01a5bc70e595c2be..d4ba0ecfce0908ae45927f01a3b07f6706fa0d3b 100644 (file)
@@ -2,7 +2,7 @@ import logging
 import random
 import time
 from pathlib import Path
-from typing import Dict, Optional
+from typing import Dict, Union
 
 import yaml
 from github import Github
@@ -18,8 +18,8 @@ class Settings(BaseSettings):
     github_repository: str
     input_token: SecretStr
     github_event_path: Path
-    github_event_name: Optional[str] = None
-    input_debug: Optional[bool] = False
+    github_event_name: Union[str, None] = None
+    input_debug: Union[bool, None] = False
 
 
 class PartialGitHubEventIssue(BaseModel):
index 9de6fc25058566746e30617c27b21a124a2eb779..1455d01caeee586fe2f6bf0123c3435e413cea6a 100644 (file)
@@ -4,7 +4,7 @@ import sys
 from collections import Counter, defaultdict
 from datetime import datetime, timedelta, timezone
 from pathlib import Path
-from typing import Container, DefaultDict, Dict, List, Optional, Set
+from typing import Container, DefaultDict, Dict, List, Set, Union
 
 import httpx
 import yaml
@@ -133,7 +133,7 @@ class Author(BaseModel):
 
 class CommentsNode(BaseModel):
     createdAt: datetime
-    author: Optional[Author] = None
+    author: Union[Author, None] = None
 
 
 class Comments(BaseModel):
@@ -142,7 +142,7 @@ class Comments(BaseModel):
 
 class IssuesNode(BaseModel):
     number: int
-    author: Optional[Author] = None
+    author: Union[Author, None] = None
     title: str
     createdAt: datetime
     state: str
@@ -179,7 +179,7 @@ class Labels(BaseModel):
 
 
 class ReviewNode(BaseModel):
-    author: Optional[Author] = None
+    author: Union[Author, None] = None
     state: str
 
 
@@ -190,7 +190,7 @@ class Reviews(BaseModel):
 class PullRequestNode(BaseModel):
     number: int
     labels: Labels
-    author: Optional[Author] = None
+    author: Union[Author, None] = None
     title: str
     createdAt: datetime
     state: str
@@ -263,7 +263,7 @@ class Settings(BaseSettings):
 
 
 def get_graphql_response(
-    *, settings: Settings, query: str, after: Optional[str] = None
+    *, settings: Settings, query: str, after: Union[str, None] = None
 ):
     headers = {"Authorization": f"token {settings.input_token.get_secret_value()}"}
     variables = {"after": after}
@@ -280,19 +280,19 @@ def get_graphql_response(
     return data
 
 
-def get_graphql_issue_edges(*, settings: Settings, after: Optional[str] = None):
+def get_graphql_issue_edges(*, settings: Settings, after: Union[str, None] = None):
     data = get_graphql_response(settings=settings, query=issues_query, after=after)
     graphql_response = IssuesResponse.parse_obj(data)
     return graphql_response.data.repository.issues.edges
 
 
-def get_graphql_pr_edges(*, settings: Settings, after: Optional[str] = None):
+def get_graphql_pr_edges(*, settings: Settings, after: Union[str, None] = None):
     data = get_graphql_response(settings=settings, query=prs_query, after=after)
     graphql_response = PRsResponse.parse_obj(data)
     return graphql_response.data.repository.pullRequests.edges
 
 
-def get_graphql_sponsor_edges(*, settings: Settings, after: Optional[str] = None):
+def get_graphql_sponsor_edges(*, settings: Settings, after: Union[str, None] = None):
     data = get_graphql_response(settings=settings, query=sponsors_query, after=after)
     graphql_response = SponsorsResponse.parse_obj(data)
     return graphql_response.data.user.sponsorshipsAsMaintainer.edges
index 3b3520599c797561b607ed4be38881408f331aec..51285d02b879d3d6e7eb06a417062c7246adf82b 100644 (file)
@@ -1,7 +1,7 @@
 import logging
 from datetime import datetime
 from pathlib import Path
-from typing import List, Optional
+from typing import List, Union
 
 import httpx
 from github import Github
@@ -16,7 +16,7 @@ class Settings(BaseSettings):
     input_token: SecretStr
     github_repository: str
     github_event_path: Path
-    github_event_name: Optional[str] = None
+    github_event_name: Union[str, None] = None
 
 
 class Artifact(BaseModel):
@@ -74,7 +74,7 @@ if __name__ == "__main__":
         logging.info(f"Docs preview was notified: {notified}")
         if not notified:
             artifact_name = f"docs-zip-{commit}"
-            use_artifact: Optional[Artifact] = None
+            use_artifact: Union[Artifact, None] = None
             for artifact in artifacts_response.artifacts:
                 if artifact.name == artifact_name:
                     use_artifact = artifact