-
Notifications
You must be signed in to change notification settings - Fork 788
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
Settings: Handle empty Groups #4576
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.
Not sure yet if we want this solution (or both), but It's less messy than the other solution, so maybe.
Co-authored-by: black-sliver <[email protected]>
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.
Thanks!
While I still believe it is probably a mistake to have an empty group, I can think of one legit reason, so in combination with the cleaner code, this probably the best solution until someone runs into other problems 😅
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.
Something is failing for me on that branch. Blocking merge for now, will update once I figured out what.
Okay, I figured out what the problem is: pokemon_emerald_settings:
{}
rom_file: "path/to/file" -- |
not sure i understand the codepath in question, but would ideal functionality "notice" that keys are going to be added and skip the empty dict write? |
settings.py
Outdated
@@ -270,6 +270,9 @@ def dump(self, f: TextIO, level: int = 0) -> None: | |||
# fetch class to avoid going through getattr | |||
cls = self.__class__ | |||
type_hints = cls.get_type_hints() | |||
if not type_hints: | |||
# write empty dict for empty Group | |||
cls._dump_value(type_hints, f, indent=" " * level) |
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.
This adds {}
if the class is empty, but loading a yaml can add values to the instance that will then get dumped in line 289.
tested with an empty host.yaml with and without emerald's settings object mangled |
Co-authored-by: black-sliver <[email protected]>
some quick testing those updates seem to work well |
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.
Reran the broken case now and works. Thanks!
What is this fixing or adding?
alternative to #4452
issue was an apworld that defined
and added it as their world.settings type hint to register it, causing late crashes
while the previous solution tried to crash the world early enough to not affect other worlds' settings, this pr instead aims to accept an empty Group as valid and to handle an empty dict type cache directly
export empty groups as an empty dict instead of crashing
How was this tested?
made emerald null out their settings class
on an empty file exported as
get_settings().pokemon_emerald_settings
returned the class which did not have attributes as expectedreverting emerald changes and re-saving the file populated the section as expected
If this makes graphical changes, please attach screenshots.