1
1
from __future__ import annotations
2
2
3
3
import abc
4
- import logging
5
- from copy import deepcopy
6
- from dataclasses import dataclass
7
4
import functools
5
+ import logging
8
6
import math
9
7
import numbers
10
8
import random
11
9
import typing
12
10
from copy import deepcopy
11
+ from dataclasses import dataclass
13
12
14
13
from schema import And , Optional , Or , Schema
15
14
16
- from Utils import get_fuzzy_results
15
+ from Utils import get_fuzzy_results , is_iterable_of_str
17
16
18
17
if typing .TYPE_CHECKING :
19
18
from BaseClasses import PlandoOptions
@@ -59,6 +58,7 @@ def __new__(mcs, name, bases, attrs):
59
58
def verify (self , * args , ** kwargs ) -> None :
60
59
for f in verifiers :
61
60
f (self , * args , ** kwargs )
61
+
62
62
attrs ["verify" ] = verify
63
63
else :
64
64
assert verifiers , "class Option is supposed to implement def verify"
@@ -183,6 +183,7 @@ def get_option_name(cls, value: str) -> str:
183
183
184
184
class NumericOption (Option [int ], numbers .Integral , abc .ABC ):
185
185
default = 0
186
+
186
187
# note: some of the `typing.Any`` here is a result of unresolved issue in python standards
187
188
# `int` is not a `numbers.Integral` according to the official typestubs
188
189
# (even though isinstance(5, numbers.Integral) == True)
@@ -598,7 +599,7 @@ def verify(self, world: typing.Type[World], player_name: str, plando_options: "P
598
599
if isinstance (self .value , int ):
599
600
return
600
601
from BaseClasses import PlandoOptions
601
- if not (PlandoOptions .bosses & plando_options ):
602
+ if not (PlandoOptions .bosses & plando_options ):
602
603
# plando is disabled but plando options were given so pull the option and change it to an int
603
604
option = self .value .split (";" )[- 1 ]
604
605
self .value = self .options [option ]
@@ -765,7 +766,7 @@ class VerifyKeys(metaclass=FreezeValidKeys):
765
766
value : typing .Any
766
767
767
768
@classmethod
768
- def verify_keys (cls , data : typing .List [str ]):
769
+ def verify_keys (cls , data : typing .Iterable [str ]) -> None :
769
770
if cls .valid_keys :
770
771
data = set (data )
771
772
dataset = set (word .casefold () for word in data ) if cls .valid_keys_casefold else set (data )
@@ -843,11 +844,11 @@ class OptionList(Option[typing.List[typing.Any]], VerifyKeys):
843
844
# If only unique entries are needed and input order of elements does not matter, OptionSet should be used instead.
844
845
# Not a docstring so it doesn't get grabbed by the options system.
845
846
846
- default : typing .List [typing .Any ] = []
847
+ default : typing .Union [ typing . List [typing .Any ], typing . Tuple [ typing . Any , ...]] = ()
847
848
supports_weighting = False
848
849
849
- def __init__ (self , value : typing .List [ typing . Any ]):
850
- self .value = deepcopy (value )
850
+ def __init__ (self , value : typing .Iterable [ str ]):
851
+ self .value = list ( deepcopy (value ) )
851
852
super (OptionList , self ).__init__ ()
852
853
853
854
@classmethod
@@ -856,7 +857,7 @@ def from_text(cls, text: str):
856
857
857
858
@classmethod
858
859
def from_any (cls , data : typing .Any ):
859
- if type (data ) == list :
860
+ if is_iterable_of_str (data ):
860
861
cls .verify_keys (data )
861
862
return cls (data )
862
863
return cls .from_text (str (data ))
@@ -882,7 +883,7 @@ def from_text(cls, text: str):
882
883
883
884
@classmethod
884
885
def from_any (cls , data : typing .Any ):
885
- if isinstance (data , ( list , set , frozenset ) ):
886
+ if is_iterable_of_str (data ):
886
887
cls .verify_keys (data )
887
888
return cls (data )
888
889
return cls .from_text (str (data ))
@@ -932,7 +933,7 @@ def __new__(mcs,
932
933
bases : typing .Tuple [type , ...],
933
934
attrs : typing .Dict [str , typing .Any ]) -> "OptionsMetaProperty" :
934
935
for attr_type in attrs .values ():
935
- assert not isinstance (attr_type , AssembleOptions ),\
936
+ assert not isinstance (attr_type , AssembleOptions ), \
936
937
f"Options for { name } should be type hinted on the class, not assigned"
937
938
return super ().__new__ (mcs , name , bases , attrs )
938
939
0 commit comments