[Config] Group.__call__() has same behaviour as Group.all() #2018

Merged
Tobotimus merged 12 commits from V3/config_group_call into V3/develop 2018-08-26 15:30:36 +02:00
Tobotimus commented 2018-08-14 06:40:40 +02:00 (Migrated from github.com)

Type

  • Bugfix

Description of the changes

This modifies config.Group.__call__ to now have the same behaviour of config.Group.all(), and in fact all() is now simply an alias for __call__. Both of these functions are able to be used as a context manager as well.

Furthermore, to match the new behaviour of __call__, get_raw will mix in defaults when a sub-group is being retrieved by it.

### Type - Bugfix ### Description of the changes This modifies `config.Group.__call__` to now have the same behaviour of `config.Group.all()`, and in fact `all()` is now simply an alias for `__call__`. Both of these functions are able to be used as a context manager as well. Furthermore, to match the new behaviour of `__call__`, `get_raw` will mix in defaults when a sub-group is being retrieved by it.
palmtree5 (Migrated from github.com) reviewed 2018-08-14 06:40:40 +02:00
tekulvw (Migrated from github.com) reviewed 2018-08-14 06:40:40 +02:00
Twentysix26 (Migrated from github.com) reviewed 2018-08-14 06:40:40 +02:00
Tobotimus commented 2018-08-16 16:37:19 +02:00 (Migrated from github.com)

Notes about breaking changes

The situations where these changes could be breaking are where you are retrieving data whose default type is a dict, by either calling a config.Group object, or using get_raw() to retrieve a dict. Previously, these functions would not return defaults mixed into the returned dict - the new behaviour is that they do.

As an example:

# old behaviour

config.register_global(foo={'bar': True})
await config.foo()  # -> {}

# new behaviour

config.register_global(foo={'bar': True})
await config.foo()  # -> {'bar': True}

And an example with get_raw():

# old behaviour

config.register_global(foo={'bar': True, 'baz': False})
await config.foo.baz.set(True)
await config.get_raw('foo')  # -> {'baz': True}

# new behaviour

config.register_global(foo={'bar': True, 'baz': False})
await config.foo.baz.set(True)
await config.get_raw('foo')  # -> {'bar': True, 'baz': True}

Concerns

If you have any concerns about how you will update to account for these changes, let us know (in #coding perhaps) and we will do our best to assist you.

### Notes about breaking changes The situations where these changes could be breaking are where you are retrieving data whose default type is a dict, by either calling a `config.Group` object, or using `get_raw()` to retrieve a dict. Previously, these functions would not return defaults mixed into the returned dict - the new behaviour is that they do. As an example: ```py # old behaviour config.register_global(foo={'bar': True}) await config.foo() # -> {} # new behaviour config.register_global(foo={'bar': True}) await config.foo() # -> {'bar': True} ``` And an example with `get_raw()`: ```py # old behaviour config.register_global(foo={'bar': True, 'baz': False}) await config.foo.baz.set(True) await config.get_raw('foo') # -> {'baz': True} # new behaviour config.register_global(foo={'bar': True, 'baz': False}) await config.foo.baz.set(True) await config.get_raw('foo') # -> {'bar': True, 'baz': True} ``` ### Concerns If you have any concerns about how you will update to account for these changes, let us know (in #coding perhaps) and we will do our best to assist you.
mikeshardmind commented 2018-08-16 16:43:58 +02:00 (Migrated from github.com)

A slight clarification, this is only a breaking change in those cases if you were using that behavior as a method for checking that no value was set. In most cases, registering a default should indicate that you have a default value and do not care if one is not already set, however, if you do care, there are a few ways to handle this.

  • Sentinel Values which will never exist in normal operation as defaults. (None for a value which can't normally be None as an example)
  • Checking the all_members, all_roles, all_guilds (etc) method for their existence.
A slight clarification, this is only a breaking change in those cases if you were using that behavior as a method for checking that no value was set. In most cases, registering a default should indicate that you have a default value and do not care if one is not already set, however, if you do care, there are a few ways to handle this. - Sentinel Values which will never exist in normal operation as defaults. (`None` for a value which can't normally be None as an example) - Checking the all_members, all_roles, all_guilds (etc) method for their existence.
mikeshardmind (Migrated from github.com) approved these changes 2018-08-16 21:42:10 +02:00
mikeshardmind (Migrated from github.com) left a comment

This looks solid and appears to be behaving with the new intended behavior. I've left a comment about a particular refactor option in the bank, but it's not a necessity to change the way this was handled, just an option for discussion.

This looks solid and appears to be behaving with the new intended behavior. I've left a comment about a particular refactor option in the bank, but it's not a necessity to change the way this was handled, just an option for discussion.
@ -405,3 +404,2 @@
else:
acc_data = (await _conf.member(member)()).copy()
default = _DEFAULT_MEMBER.copy()
all_accounts = await _conf.all_members(member.guild)
mikeshardmind (Migrated from github.com) commented 2018-08-16 21:39:22 +02:00

Would it make more sense to use a context manager with a sentinel value default for account creation which would be impossible? It's not a required change, but it should simplify the new user case significantly.

Would it make more sense to use a context manager with a sentinel value default for account creation which would be impossible? It's not a required change, but it should simplify the new user case significantly.
Tobotimus (Migrated from github.com) reviewed 2018-08-17 03:58:05 +02:00
@ -405,3 +404,2 @@
else:
acc_data = (await _conf.member(member)()).copy()
default = _DEFAULT_MEMBER.copy()
all_accounts = await _conf.all_members(member.guild)
Tobotimus (Migrated from github.com) commented 2018-08-17 03:58:05 +02:00

That's true. For now this works so I'm going to leave it as it is, however sentinel values are possible as defaults... You just need to be careful whether you specify a sentinel value as an empty dict, or None.

When using a NoneType sentinel value, that value will not be treated as a config.Group, even if a dict later replaces it. Using an empty dict instead, the value will be treated as a config.Group, and programmers can utilise the extra methods of this object.

That's true. For now this works so I'm going to leave it as it is, however sentinel values are possible as defaults... You just need to be careful whether you specify a sentinel value as an empty dict, or `None`. When using a `NoneType` sentinel value, that value will not be treated as a `config.Group`, even if a dict later replaces it. Using an empty dict instead, the value will be treated as a `config.Group`, and programmers can utilise the extra methods of this object.
Kowlin (Migrated from github.com) approved these changes 2018-08-26 15:10:34 +02:00
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot!2018
No description provided.