-
Notifications
You must be signed in to change notification settings - Fork 723
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
Utils: Fix mistake made with KeyedDefaultDict
from #1933 that broke tracker functionality.
#3433
Conversation
… that broke tracker functionality.
KeyedDefaultDict
from #1933 that broke…KeyedDefaultDict
from #1933 that broke tracker functionality.
If what you have solves the immediate problem, it might be best to merge it and work on the typing later, just to get things fixed. But if you want to get correct typing, you can try this. I ran unit tests with it and looked at references, but you might know better than me how to test it well. KT = typing.TypeVar("KT")
VT = typing.TypeVar("VT")
class KeyedDefaultDict(Dict[KT, VT]):
"""something like defaultdict that uses the missing key as argument to default_factory"""
default_factory: typing.Callable[[KT], VT]
def __init__(self,
default_factory: typing.Callable[[KT], VT],
mapping: typing.Union[typing.Mapping[KT, VT], typing.Iterable[typing.Tuple[KT, VT]], None] = None,
**kwargs: VT) -> None:
self.default_factory = default_factory
if mapping is not None:
super().__init__(mapping, **kwargs)
else:
super().__init__(**kwargs)
def __missing__(self, key: KT) -> VT:
self[key] = value = self.default_factory(key)
return value I don't see a good reason to be inheriting from I also don't see a good reason to allow not giving a |
For now, I'm going to merge this to fix the bug currently affecting the tracker. We can revisit improving the typing in another PR. |
… that broke tracker functionality. (ArchipelagoMW#3433)
… that broke tracker functionality. (ArchipelagoMW#3433)
… that broke tracker functionality. (ArchipelagoMW#3433)
… that broke tracker functionality. (ArchipelagoMW#3433)
… that broke tracker functionality. (ArchipelagoMW#3433)
What is this fixing or adding?
During #1933, I defined a custom
__init__
forUtils.KeyedDefaultDict
to make PyCharm happy when creating a new dict, but forgot to add a*args
param, which was only utilized in the tracker code, so I missed in testing. This adds it and fixes the 500 server error that gets displayed on multitracker.How was this tested?
Ran WebHost before and after.
If this makes graphical changes, please attach screenshots.
Before:
After:
:P