Core: typing for Option.default and a few other ClassVars (#2899)

* Core: typing for `Option.default` and a few other `Option` class variables

This is a replacement for https://github.com/ArchipelagoMW/Archipelago/pull/2173

You can read discussion there for issues we found for why we can't have more specific typing on `default`

instead of setting a default in `Option` (where we don't know the type), we check in the metaclass to make sure they have a default.

* NumericOption doesn't need the type annotation that brings out the mypy bug

* SoE default ClassVar
This commit is contained in:
Doug Hoskisson
2024-03-12 14:03:57 -07:00
committed by GitHub
parent f8d5fe0e1e
commit 03d403ff51
2 changed files with 17 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
from dataclasses import dataclass, fields
from typing import Any, cast, Dict, Iterator, List, Tuple, Protocol
from typing import Any, ClassVar, cast, Dict, Iterator, List, Tuple, Protocol
from Options import AssembleOptions, Choice, DeathLink, DefaultOnToggle, Option, PerGameCommonOptions, \
ProgressionBalancing, Range, Toggle
@@ -8,13 +8,13 @@ from Options import AssembleOptions, Choice, DeathLink, DefaultOnToggle, Option,
# typing boilerplate
class FlagsProtocol(Protocol):
value: int
default: int
default: ClassVar[int]
flags: List[str]
class FlagProtocol(Protocol):
value: int
default: int
default: ClassVar[int]
flag: str