Docs: More type annotation changes (#5301)
* Update docs annotations * Update settings recommendation * Remove Dict in comment
This commit is contained in:
@@ -352,14 +352,14 @@ direction_matching_group_lookup = {
|
|||||||
|
|
||||||
Terrain matching or dungeon shuffle:
|
Terrain matching or dungeon shuffle:
|
||||||
```python
|
```python
|
||||||
def randomize_within_same_group(group: int) -> List[int]:
|
def randomize_within_same_group(group: int) -> list[int]:
|
||||||
return [group]
|
return [group]
|
||||||
identity_group_lookup = bake_target_group_lookup(world, randomize_within_same_group)
|
identity_group_lookup = bake_target_group_lookup(world, randomize_within_same_group)
|
||||||
```
|
```
|
||||||
|
|
||||||
Directional + area shuffle:
|
Directional + area shuffle:
|
||||||
```python
|
```python
|
||||||
def get_target_groups(group: int) -> List[int]:
|
def get_target_groups(group: int) -> list[int]:
|
||||||
# example group: LEFT | CAVE
|
# example group: LEFT | CAVE
|
||||||
# example result: [RIGHT | CAVE, DOOR | CAVE]
|
# example result: [RIGHT | CAVE, DOOR | CAVE]
|
||||||
direction = group & Groups.DIRECTION_MASK
|
direction = group & Groups.DIRECTION_MASK
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ Sent to clients when they connect to an Archipelago server.
|
|||||||
| generator_version | [NetworkVersion](#NetworkVersion) | Object denoting the version of Archipelago which generated the multiworld. |
|
| generator_version | [NetworkVersion](#NetworkVersion) | Object denoting the version of Archipelago which generated the multiworld. |
|
||||||
| tags | list\[str\] | Denotes special features or capabilities that the sender is capable of. Example: `WebHost` |
|
| tags | list\[str\] | Denotes special features or capabilities that the sender is capable of. Example: `WebHost` |
|
||||||
| password | bool | Denoted whether a password is required to join this room. |
|
| password | bool | Denoted whether a password is required to join this room. |
|
||||||
| permissions | dict\[str, [Permission](#Permission)\[int\]\] | Mapping of permission name to [Permission](#Permission), keys are: "release", "collect" and "remaining". |
|
| permissions | dict\[str, [Permission](#Permission)\] | Mapping of permission name to [Permission](#Permission), keys are: "release", "collect" and "remaining". |
|
||||||
| hint_cost | int | The percentage of total locations that need to be checked to receive a hint from the server. |
|
| hint_cost | int | The percentage of total locations that need to be checked to receive a hint from the server. |
|
||||||
| location_check_points | int | The amount of hint points you receive per item/location check completed. |
|
| location_check_points | int | The amount of hint points you receive per item/location check completed. |
|
||||||
| games | list\[str\] | List of games present in this multiworld. |
|
| games | list\[str\] | List of games present in this multiworld. |
|
||||||
@@ -662,13 +662,14 @@ class SlotType(enum.IntFlag):
|
|||||||
An object representing static information about a slot.
|
An object representing static information about a slot.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import typing
|
from collections.abc import Sequence
|
||||||
|
from typing import NamedTuple
|
||||||
from NetUtils import SlotType
|
from NetUtils import SlotType
|
||||||
class NetworkSlot(typing.NamedTuple):
|
class NetworkSlot(NamedTuple):
|
||||||
name: str
|
name: str
|
||||||
game: str
|
game: str
|
||||||
type: SlotType
|
type: SlotType
|
||||||
group_members: typing.List[int] = [] # only populated if type == group
|
group_members: Sequence[int] = [] # only populated if type == group
|
||||||
```
|
```
|
||||||
|
|
||||||
### Permission
|
### Permission
|
||||||
@@ -686,8 +687,8 @@ class Permission(enum.IntEnum):
|
|||||||
### Hint
|
### Hint
|
||||||
An object representing a Hint.
|
An object representing a Hint.
|
||||||
```python
|
```python
|
||||||
import typing
|
from typing import NamedTuple
|
||||||
class Hint(typing.NamedTuple):
|
class Hint(NamedTuple):
|
||||||
receiving_player: int
|
receiving_player: int
|
||||||
finding_player: int
|
finding_player: int
|
||||||
location: int
|
location: int
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ if it does not exist.
|
|||||||
## Global Settings
|
## Global Settings
|
||||||
|
|
||||||
All non-world-specific settings are defined directly in settings.py.
|
All non-world-specific settings are defined directly in settings.py.
|
||||||
Each value needs to have a default. If the default should be `None`, define it as `typing.Optional` and assign `None`.
|
Each value needs to have a default. If the default should be `None`, annotate it using `T | None = None`.
|
||||||
|
|
||||||
To access a "global" config value, with correct typing, use one of
|
To access a "global" config value, with correct typing, use one of
|
||||||
```python
|
```python
|
||||||
|
|||||||
@@ -15,8 +15,10 @@
|
|||||||
* Prefer [format string literals](https://peps.python.org/pep-0498/) over string concatenation,
|
* Prefer [format string literals](https://peps.python.org/pep-0498/) over string concatenation,
|
||||||
use single quotes inside them: `f"Like {dct['key']}"`
|
use single quotes inside them: `f"Like {dct['key']}"`
|
||||||
* Use type annotations where possible for function signatures and class members.
|
* Use type annotations where possible for function signatures and class members.
|
||||||
* Use type annotations where appropriate for local variables (e.g. `var: List[int] = []`, or when the
|
* Use type annotations where appropriate for local variables (e.g. `var: list[int] = []`, or when the
|
||||||
type is hard or impossible to deduce.) Clear annotations help developers look up and validate API calls.
|
type is hard or impossible to deduce). Clear annotations help developers look up and validate API calls.
|
||||||
|
* Prefer new style type annotations for new code (e.g. `var: dict[str, str | int]` over
|
||||||
|
`var: Dict[str, Union[str, int]]`).
|
||||||
* If a line ends with an open bracket/brace/parentheses, the matching closing bracket should be at the
|
* If a line ends with an open bracket/brace/parentheses, the matching closing bracket should be at the
|
||||||
beginning of a line at the same indentation as the beginning of the line with the open bracket.
|
beginning of a line at the same indentation as the beginning of the line with the open bracket.
|
||||||
```python
|
```python
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ webhost:
|
|||||||
* `game_info_languages` (optional) list of strings for defining the existing game info pages your game supports. The
|
* `game_info_languages` (optional) list of strings for defining the existing game info pages your game supports. The
|
||||||
documents must be prefixed with the same string as defined here. Default already has 'en'.
|
documents must be prefixed with the same string as defined here. Default already has 'en'.
|
||||||
|
|
||||||
* `options_presets` (optional) `Dict[str, Dict[str, Any]]` where the keys are the names of the presets and the values
|
* `options_presets` (optional) `dict[str, dict[str, Any]]` where the keys are the names of the presets and the values
|
||||||
are the options to be set for that preset. The options are defined as a `Dict[str, Any]` where the keys are the names
|
are the options to be set for that preset. The options are defined as a `dict[str, Any]` where the keys are the names
|
||||||
of the options and the values are the values to be set for that option. These presets will be available for users to
|
of the options and the values are the values to be set for that option. These presets will be available for users to
|
||||||
select from on the game's options page.
|
select from on the game's options page.
|
||||||
|
|
||||||
@@ -753,7 +753,7 @@ from BaseClasses import CollectionState, MultiWorld
|
|||||||
from worlds.AutoWorld import LogicMixin
|
from worlds.AutoWorld import LogicMixin
|
||||||
|
|
||||||
class MyGameState(LogicMixin):
|
class MyGameState(LogicMixin):
|
||||||
mygame_defeatable_enemies: Dict[int, Set[str]] # per player
|
mygame_defeatable_enemies: dict[int, set[str]] # per player
|
||||||
|
|
||||||
def init_mixin(self, multiworld: MultiWorld) -> None:
|
def init_mixin(self, multiworld: MultiWorld) -> None:
|
||||||
# Initialize per player with the corresponding "nothing" value, such as 0 or an empty set.
|
# Initialize per player with the corresponding "nothing" value, such as 0 or an empty set.
|
||||||
@@ -882,11 +882,11 @@ item/location pairs is unnecessary since the AP server already retains and freel
|
|||||||
that request it. The most common usage of slot data is sending option results that the client needs to be aware of.
|
that request it. The most common usage of slot data is sending option results that the client needs to be aware of.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def fill_slot_data(self) -> Dict[str, Any]:
|
def fill_slot_data(self) -> dict[str, Any]:
|
||||||
# In order for our game client to handle the generated seed correctly we need to know what the user selected
|
# In order for our game client to handle the generated seed correctly we need to know what the user selected
|
||||||
# for their difficulty and final boss HP.
|
# for their difficulty and final boss HP.
|
||||||
# A dictionary returned from this method gets set as the slot_data and will be sent to the client after connecting.
|
# A dictionary returned from this method gets set as the slot_data and will be sent to the client after connecting.
|
||||||
# The options dataclass has a method to return a `Dict[str, Any]` of each option name provided and the relevant
|
# The options dataclass has a method to return a `dict[str, Any]` of each option name provided and the relevant
|
||||||
# option's value.
|
# option's value.
|
||||||
return self.options.as_dict("difficulty", "final_boss_hp")
|
return self.options.as_dict("difficulty", "final_boss_hp")
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user