Skip to content
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

Merged
merged 5 commits into from
Jun 3, 2024

Conversation

ThePhar
Copy link
Member

@ThePhar ThePhar commented Jun 1, 2024

What is this fixing or adding?

During #1933, I defined a custom __init__ for Utils.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:
image

After:
image

:P

@ThePhar ThePhar added is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. affects: core Issues/PRs that touch core and may need additional validation. affects: release/blocker Issues/PRs that must be addressed before next official release. affects: webhost Issues/PRs that touch webhost and may need additional validation. labels Jun 1, 2024
@ThePhar ThePhar changed the title Utils: Fix mistake made with KeyedDefaultDict from #1933 that broke… Utils: Fix mistake made with KeyedDefaultDict from #1933 that broke tracker functionality. Jun 1, 2024
@github-actions github-actions bot added the waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. label Jun 1, 2024
@beauxq
Copy link
Collaborator

beauxq commented Jun 2, 2024

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 defaultdict
The typing of default_factory is definitely incompatible with it.

I also don't see a good reason to allow not giving a default_factory to __init__
(If you don't have a default_factory why would you use this class?)

@ThePhar
Copy link
Member Author

ThePhar commented Jun 3, 2024

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.

@ThePhar ThePhar merged commit cff7327 into ArchipelagoMW:main Jun 3, 2024
15 of 16 checks passed
@ThePhar ThePhar deleted the fix_boneheaded_mistake branch June 3, 2024 08:45
wu4 pushed a commit to wu4/Archipelago that referenced this pull request Jun 6, 2024
agilbert1412 pushed a commit to agilbert1412/Archipelago that referenced this pull request Jun 13, 2024
jnschurig pushed a commit to Tranquilite0/Archipelago-SoulBlazer that referenced this pull request Jun 13, 2024
sflavelle pushed a commit to sflavelle/Archipelago-tgc that referenced this pull request Jun 20, 2024
qwint pushed a commit to qwint/Archipelago that referenced this pull request Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. affects: release/blocker Issues/PRs that must be addressed before next official release. affects: webhost Issues/PRs that touch webhost and may need additional validation. is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants