-
Notifications
You must be signed in to change notification settings - Fork 994
Core: Allow common collections in OptionSet and OptionList constructors #2874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Core: Allow common collections in OptionSet and OptionList constructors #2874
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, idea seems reasonable
…in-option-parsing allow any iterable of strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked over all of these changes with linting and type checking and thinking about the logic, and it looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides typing, basically only changes an isinstance() and adds a list() and those seem to be correct.seems to be correct.
def __init__(self, value: typing.List[typing.Any]): | ||
self.value = deepcopy(value) | ||
def __init__(self, value: typing.Iterable[str]): | ||
self.value = list(deepcopy(value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have noticed this. You changed the type var from Any
to str
, and I trusted it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed it as well. We can at least partially blame the lack of unit tests :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I should have checked deeper how this was used. Definitely my bad on this one.
…rs (ArchipelagoMW#2874) * allow common collection in set and list option constructors * allow any iterable of strings * add return None --------- Co-authored-by: beauxq <[email protected]>
…rs (ArchipelagoMW#2874) * allow common collection in set and list option constructors * allow any iterable of strings * add return None --------- Co-authored-by: beauxq <[email protected]>
What is this fixing or adding?
Allow for usage of
set
,list
,frozenset
andtuple
in.from_any(data)
factory methods ofOptionSet
andOptionList
.I needed to add
tuple
support specifically toOptionSet
, to use the.from_any(data)
to parse the options, specifically the Mods combinations generated withitertools.combination()
.Currently, if
OptionSet.from_any(...)
is called with atuple
, it is stringnified. For instance, that causes the tuple("DeepWoods", "Tractor Mod")
to be transformed into'("DeepWoods", "Tractor Mod")'
, which is then split on the,
to create theOptionSet
with the values'("DeepWoods"'
and' "Tractor Mod")'
, which are very obviously invalid. To add more to the issue, the validation is not even called because it fallbacks on the.from_text(...)
factory method. This issue went unnoticed for weeks in our dev branch.I could have changed the
tuple
to aset
in each test, but it seems much simpler if the core supports it. Parsing and validation issues are solved at once.One of the tests in question, FYI
Even if this technically adds an explicit dependency on
typing-extensions
, it was already a transitive dependency ofFlask-Limiter
, so it's not really a new dependency.How was this tested?
Ran the tests, generated a plando seed with Stardew and Dark Souls III, plus generated a seed with all currently supported game (default options).
Honestly, those types are not even used with
Generate.py
, so I have big doubts it actually changes anything for generation in general, beside the insignificant performance drop from changingtype(data) == list
toisinstance
.If this makes graphical changes, please attach screenshots.
No graphical changes