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

Core: Add dict functionality to OptionDict #2036

Merged
merged 3 commits into from
Jul 30, 2023

Conversation

alwaysintreble
Copy link
Collaborator

What is this fixing or adding?

Title. It seemed weird to me that these aren't really supported by the "OptionDict". I think if you make something that isn't actually a dict, you probably know to override or not use these.

How was this tested?

Put it in The Messenger and generated a few seeds/debugged.

If this makes graphical changes, please attach screenshots.

@el-u
Copy link
Collaborator

el-u commented Jul 26, 2023

Instead of selectively implementing some methods, you might want to consider the Mapping ABC if you really want OptionsDict to behave more like an actual dict. It automatically provides implementations for various dict-like methods (__contains__, keys, items, values, get, __eq__, and __ne__) while only requiring 3 abstract methods to be actually implemented explicitly (__getitem__, __iter__, and __len__).

See here for an example.

@ThePhar ThePhar added is: enhancement Issues requesting new features or pull requests implementing new features. affects: core Issues/PRs that touch core and may need additional validation. labels Jul 26, 2023
@ThePhar ThePhar changed the title Options: Add support for items() and __getitem__ to OptionDict Core: Add support for items() and __getitem__ to OptionDict Jul 26, 2023
@alwaysintreble alwaysintreble changed the title Core: Add support for items() and __getitem__ to OptionDict Core: Add dict functionality to OptionDict Jul 27, 2023
Options.py Outdated Show resolved Hide resolved
Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
@black-sliver black-sliver merged commit cacfd4f into ArchipelagoMW:main Jul 30, 2023
12 checks passed
@alwaysintreble alwaysintreble deleted the dict_getitem branch October 12, 2023 11:23
FlySniper pushed a commit to FlySniper/Archipelago that referenced this pull request Nov 14, 2023
* Options: Add support for `items()` and `__getitem__` to OptionDict

* Options: have OptionDict inherit from Mapping

* add typing to __getitem__

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>

---------

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
kl3cks7r pushed a commit to kl3cks7r/Archipelago that referenced this pull request Dec 15, 2023
* Options: Add support for `items()` and `__getitem__` to OptionDict

* Options: have OptionDict inherit from Mapping

* add typing to __getitem__

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>

---------

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
Jouramie pushed a commit to Jouramie/Archipelago that referenced this pull request Feb 28, 2024
* Options: Add support for `items()` and `__getitem__` to OptionDict

* Options: have OptionDict inherit from Mapping

* add typing to __getitem__

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>

---------

Co-authored-by: black-sliver <59490463+black-sliver@users.noreply.github.com>
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. is: enhancement Issues requesting new features or pull requests implementing new features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants