The Witness: Change Regions, Areas and Connections from Dict[str, Any] to dataclasses&NamedTuples (#4415)

* Change Regions, Areas and Connections to dataclasses/NamedTuples

* Move to new file

* we do a little renaming

* Purge the 'lambda' naming in favor of 'rule' or 'WitnessRule'

* missed one

* unnecessary change

* omega oops

* NOOOOOOOO

* Merge error

* mypy thing
This commit is contained in:
NewSoupVi
2025-03-13 23:59:09 +01:00
committed by GitHub
parent 3192799bbf
commit 1de411ec89
11 changed files with 148 additions and 125 deletions

View File

@@ -0,0 +1,33 @@
from dataclasses import dataclass, field
from typing import FrozenSet, List, NamedTuple
# A WitnessRule is just an or-chain of and-conditions.
# It represents the set of all options that could fulfill this requirement.
# E.g. if something requires "Dots or (Shapers and Stars)", it'd be represented as: {{"Dots"}, {"Shapers, "Stars"}}
# {} is an unusable requirement.
# {{}} is an always usable requirement.
WitnessRule = FrozenSet[FrozenSet[str]]
@dataclass
class AreaDefinition:
name: str
regions: List[str] = field(default_factory=list)
@dataclass
class RegionDefinition:
name: str
short_name: str
area: AreaDefinition
logical_entities: List[str] = field(default_factory=list)
physical_entities: List[str] = field(default_factory=list)
class ConnectionDefinition(NamedTuple):
target_region: str
traversal_rule: WitnessRule
@property
def can_be_traversed(self) -> bool:
return bool(self.traversal_rule)