From 653ee2b625cc64461589abe3c836e87f3ca21bc3 Mon Sep 17 00:00:00 2001 From: Nicholas Saylor <79181893+nicholassaylor@users.noreply.github.com> Date: Thu, 22 May 2025 15:00:30 -0400 Subject: [PATCH] Docs: Update Snippets to Modern Type Hints (#4987) --- docs/network protocol.md | 24 ++++++++++++------------ docs/options api.md | 2 +- docs/settings api.md | 11 +++++------ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/docs/network protocol.md b/docs/network protocol.md index 6688c101..8c07ff10 100644 --- a/docs/network protocol.md +++ b/docs/network protocol.md @@ -231,11 +231,11 @@ Sent to clients after a client requested this message be sent to them, more info Sent to clients if the server caught a problem with a packet. This only occurs for errors that are explicitly checked for. #### Arguments -| Name | Type | Notes | -| ---- | ---- | ----- | -| type | str | The [PacketProblemType](#PacketProblemType) that was detected in the packet. | -| original_cmd | Optional[str] | The `cmd` argument of the faulty packet, will be `None` if the `cmd` failed to be parsed. | -| text | str | A descriptive message of the problem at hand. | +| Name | Type | Notes | +| ---- |-------------| ----- | +| type | str | The [PacketProblemType](#PacketProblemType) that was detected in the packet. | +| original_cmd | str \| None | The `cmd` argument of the faulty packet, will be `None` if the `cmd` failed to be parsed. | +| text | str | A descriptive message of the problem at hand. | ##### PacketProblemType `PacketProblemType` indicates the type of problem that was detected in the faulty packet, the known problem types are below but others may be added in the future. @@ -551,14 +551,14 @@ In JSON this may look like: Message nodes sent along with [PrintJSON](#PrintJSON) packet to be reconstructed into a legible message. The nodes are intended to be read in the order they are listed in the packet. ```python -from typing import TypedDict, Optional +from typing import TypedDict class JSONMessagePart(TypedDict): - type: Optional[str] - text: Optional[str] - color: Optional[str] # only available if type is a color - flags: Optional[int] # only available if type is an item_id or item_name - player: Optional[int] # only available if type is either item or location - hint_status: Optional[HintStatus] # only available if type is hint_status + type: str | None + text: str | None + color: str | None # only available if type is a color + flags: int | None # only available if type is an item_id or item_name + player: int | None # only available if type is either item or location + hint_status: HintStatus | None # only available if type is hint_status ``` `type` is used to denote the intent of the message part. This can be used to indicate special information which may be rendered differently depending on client. How these types are displayed in Archipelago's ALttP client is not the end-all be-all. Other clients may choose to interpret and display these messages differently. diff --git a/docs/options api.md b/docs/options api.md index 037b9edb..c9b7c422 100644 --- a/docs/options api.md +++ b/docs/options api.md @@ -333,7 +333,7 @@ within the world. ### TextChoice Like choice allows you to predetermine options and has all of the same comparison methods and handling. Also accepts any user defined string as a valid option, so will either need to be validated by adding a validation step to the option -class or within world, if necessary. Value for this class is `Union[str, int]` so if you need the value at a specified +class or within world, if necessary. Value for this class is `str | int` so if you need the value at a specified point, `self.options.my_option.current_key` will always return a string. ### PlandoBosses diff --git a/docs/settings api.md b/docs/settings api.md index bfc642d4..ef1f20d0 100644 --- a/docs/settings api.md +++ b/docs/settings api.md @@ -102,17 +102,16 @@ In worlds, this should only be used for the top level to avoid issues when upgra ### Bool -Since `bool` can not be subclassed, use the `settings.Bool` helper in a `typing.Union` to get a comment in host.yaml. +Since `bool` can not be subclassed, use the `settings.Bool` helper in a union to get a comment in host.yaml. ```python import settings -import typing class MySettings(settings.Group): class MyBool(settings.Bool): """Doc string""" - my_value: typing.Union[MyBool, bool] = True + my_value: MyBool | bool = True ``` ### UserFilePath @@ -134,15 +133,15 @@ Checks the file against [md5s](#md5s) by default. Resolves to an executable (varying file extension based on platform) -#### description: Optional\[str\] +#### description: str | None Human-readable name to use in file browser -#### copy_to: Optional\[str\] +#### copy_to: str | None Instead of storing the path, copy the file. -#### md5s: List[Union[str, bytes]] +#### md5s: list[str | bytes] Provide md5 hashes as hex digests or raw bytes for automatic validation.