mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-18 13:27:45 -04:00
🎨 Upgrade typing syntax for Python 3.10 (#14932)
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: tiangolo <1326112+tiangolo@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
6e5680c7ea
commit
faee822574
@@ -1,5 +1,5 @@
|
||||
import re
|
||||
from typing import TypedDict, Union
|
||||
from typing import TypedDict
|
||||
|
||||
CODE_INCLUDE_RE = re.compile(r"^\{\*\s*(\S+)\s*(.*)\*\}$")
|
||||
CODE_INCLUDE_PLACEHOLDER = "<CODE_INCLUDE>"
|
||||
@@ -50,8 +50,8 @@ class MarkdownLinkInfo(TypedDict):
|
||||
line_no: int
|
||||
url: str
|
||||
text: str
|
||||
title: Union[str, None]
|
||||
attributes: Union[str, None]
|
||||
title: str | None
|
||||
attributes: str | None
|
||||
full_match: str
|
||||
|
||||
|
||||
@@ -287,8 +287,8 @@ def _add_lang_code_to_url(url: str, lang_code: str) -> str:
|
||||
def _construct_markdown_link(
|
||||
url: str,
|
||||
text: str,
|
||||
title: Union[str, None],
|
||||
attributes: Union[str, None],
|
||||
title: str | None,
|
||||
attributes: str | None,
|
||||
lang_code: str,
|
||||
) -> str:
|
||||
"""
|
||||
@@ -549,7 +549,7 @@ def extract_multiline_code_blocks(text: list[str]) -> list[MultilineCodeBlockInf
|
||||
return blocks
|
||||
|
||||
|
||||
def _split_hash_comment(line: str) -> tuple[str, Union[str, None]]:
|
||||
def _split_hash_comment(line: str) -> tuple[str, str | None]:
|
||||
match = HASH_COMMENT_RE.match(line)
|
||||
if match:
|
||||
code = match.group("code").rstrip()
|
||||
@@ -558,7 +558,7 @@ def _split_hash_comment(line: str) -> tuple[str, Union[str, None]]:
|
||||
return line.rstrip(), None
|
||||
|
||||
|
||||
def _split_slashes_comment(line: str) -> tuple[str, Union[str, None]]:
|
||||
def _split_slashes_comment(line: str) -> tuple[str, str | None]:
|
||||
match = SLASHES_COMMENT_RE.match(line)
|
||||
if match:
|
||||
code = match.group("code").rstrip()
|
||||
@@ -603,9 +603,9 @@ def replace_multiline_code_block(
|
||||
return block_a["content"].copy() # We don't handle mermaid code blocks for now
|
||||
|
||||
code_block: list[str] = []
|
||||
for line_a, line_b in zip(block_a["content"], block_b["content"]):
|
||||
line_a_comment: Union[str, None] = None
|
||||
line_b_comment: Union[str, None] = None
|
||||
for line_a, line_b in zip(block_a["content"], block_b["content"], strict=False):
|
||||
line_a_comment: str | None = None
|
||||
line_b_comment: str | None = None
|
||||
|
||||
# Handle comments based on language
|
||||
if block_language in {
|
||||
@@ -659,7 +659,7 @@ def replace_multiline_code_blocks_in_text(
|
||||
)
|
||||
|
||||
modified_text = text.copy()
|
||||
for block, original_block in zip(code_blocks, original_code_blocks):
|
||||
for block, original_block in zip(code_blocks, original_code_blocks, strict=True):
|
||||
updated_content = replace_multiline_code_block(block, original_block)
|
||||
|
||||
start_line_index = block["start_line_no"] - 1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Any, Union
|
||||
from typing import Any
|
||||
|
||||
import material
|
||||
from mkdocs.config.defaults import MkDocsConfig
|
||||
@@ -105,9 +105,9 @@ def on_files(files: Files, *, config: MkDocsConfig) -> Files:
|
||||
|
||||
|
||||
def generate_renamed_section_items(
|
||||
items: list[Union[Page, Section, Link]], *, config: MkDocsConfig
|
||||
) -> list[Union[Page, Section, Link]]:
|
||||
new_items: list[Union[Page, Section, Link]] = []
|
||||
items: list[Page | Section | Link], *, config: MkDocsConfig
|
||||
) -> list[Page | Section | Link]:
|
||||
new_items: list[Page | Section | Link] = []
|
||||
for item in items:
|
||||
if isinstance(item, Section):
|
||||
new_title = item.title
|
||||
|
||||
@@ -3,7 +3,7 @@ import random
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Any, Union, cast
|
||||
from typing import Any, cast
|
||||
|
||||
import httpx
|
||||
from github import Github
|
||||
@@ -181,9 +181,9 @@ class Settings(BaseSettings):
|
||||
github_repository: str
|
||||
github_token: SecretStr
|
||||
github_event_path: Path
|
||||
github_event_name: Union[str, None] = None
|
||||
github_event_name: str | None = None
|
||||
httpx_timeout: int = 30
|
||||
debug: Union[bool, None] = False
|
||||
debug: bool | None = False
|
||||
number: int | None = None
|
||||
|
||||
|
||||
@@ -199,12 +199,12 @@ def get_graphql_response(
|
||||
*,
|
||||
settings: Settings,
|
||||
query: str,
|
||||
after: Union[str, None] = None,
|
||||
category_id: Union[str, None] = None,
|
||||
discussion_number: Union[int, None] = None,
|
||||
discussion_id: Union[str, None] = None,
|
||||
comment_id: Union[str, None] = None,
|
||||
body: Union[str, None] = None,
|
||||
after: str | None = None,
|
||||
category_id: str | None = None,
|
||||
discussion_number: int | None = None,
|
||||
discussion_id: str | None = None,
|
||||
comment_id: str | None = None,
|
||||
body: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
headers = {"Authorization": f"token {settings.github_token.get_secret_value()}"}
|
||||
variables = {
|
||||
@@ -249,7 +249,7 @@ def get_graphql_translation_discussions(
|
||||
|
||||
|
||||
def get_graphql_translation_discussion_comments_edges(
|
||||
*, settings: Settings, discussion_number: int, after: Union[str, None] = None
|
||||
*, settings: Settings, discussion_number: int, after: str | None = None
|
||||
) -> list[CommentsEdge]:
|
||||
data = get_graphql_response(
|
||||
settings=settings,
|
||||
@@ -372,8 +372,8 @@ def main() -> None:
|
||||
f"Found a translation discussion for language: {lang} in discussion: #{discussion.number}"
|
||||
)
|
||||
|
||||
already_notified_comment: Union[Comment, None] = None
|
||||
already_done_comment: Union[Comment, None] = None
|
||||
already_notified_comment: Comment | None = None
|
||||
already_done_comment: Comment | None = None
|
||||
|
||||
logging.info(
|
||||
f"Checking current comments in discussion: #{discussion.number} to see if already notified about this PR: #{pr.number}"
|
||||
|
||||
@@ -6,7 +6,7 @@ from collections import Counter
|
||||
from collections.abc import Container
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any, Union
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
import yaml
|
||||
@@ -70,7 +70,7 @@ class Author(BaseModel):
|
||||
|
||||
class CommentsNode(BaseModel):
|
||||
createdAt: datetime
|
||||
author: Union[Author, None] = None
|
||||
author: Author | None = None
|
||||
|
||||
|
||||
class Replies(BaseModel):
|
||||
@@ -89,7 +89,7 @@ class DiscussionsComments(BaseModel):
|
||||
|
||||
class DiscussionsNode(BaseModel):
|
||||
number: int
|
||||
author: Union[Author, None] = None
|
||||
author: Author | None = None
|
||||
title: str | None = None
|
||||
createdAt: datetime
|
||||
comments: DiscussionsComments
|
||||
@@ -127,8 +127,8 @@ def get_graphql_response(
|
||||
*,
|
||||
settings: Settings,
|
||||
query: str,
|
||||
after: Union[str, None] = None,
|
||||
category_id: Union[str, None] = None,
|
||||
after: str | None = None,
|
||||
category_id: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
headers = {"Authorization": f"token {settings.github_token.get_secret_value()}"}
|
||||
variables = {"after": after, "category_id": category_id}
|
||||
@@ -156,7 +156,7 @@ def get_graphql_response(
|
||||
def get_graphql_question_discussion_edges(
|
||||
*,
|
||||
settings: Settings,
|
||||
after: Union[str, None] = None,
|
||||
after: str | None = None,
|
||||
) -> list[DiscussionsEdge]:
|
||||
data = get_graphql_response(
|
||||
settings=settings,
|
||||
|
||||
Reference in New Issue
Block a user