[Config] Group.__call__() has same behaviour as Group.all() #2018
No reviewers
Labels
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 project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!2018
Loading…
Reference in a new issue
No description provided.
Delete branch "V3/config_group_call"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Description of the changes
This modifies
config.Group.__call__to now have the same behaviour ofconfig.Group.all(), and in factall()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_rawwill mix in defaults when a sub-group is being retrieved by it.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.Groupobject, or usingget_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:
And an example with
get_raw():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.
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.
Nonefor a value which can't normally be None as an example)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)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.
@ -405,3 +404,2 @@else:acc_data = (await _conf.member(member)()).copy()default = _DEFAULT_MEMBER.copy()all_accounts = await _conf.all_members(member.guild)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
NoneTypesentinel value, that value will not be treated as aconfig.Group, even if a dict later replaces it. Using an empty dict instead, the value will be treated as aconfig.Group, and programmers can utilise the extra methods of this object.