[V3/Config] New config methods #2185
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 milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!2185
Loading…
Reference in a new issue
No description provided.
Delete branch "V3/develop"
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 adds some quality of life methods to config. The two new operations are
incandtoggle. These work likeset, but for specific value types. They also return the new value. This aims to solve repetition in calling.Examples for Incrementing
Example for Toggle
Example of doing this without these methods
I included some tests, and this is working with the both the json and mongo drivers. This shouldn't break any current usage of config.
DISCLAIMER
I'm setting this up to be implemented in 3.1 and not prior to release.
Thanks for this PR, these new methods are awesome 👍 All I found from browsing the code was 1 thing, I'll do more local tests in the next few days 😃
Once I've approved this I'll merge it into a feature branch as you suggested to me earlier.
@ -388,0 +416,4 @@with pytest.raises(TypeError):await config.foo.inc(10)with pytest.raises(TypeError):await config.baz.inc(10)These two operations should be in separate
withstatements;pytest.raiseswill catch the first exception then exit the context manager@ -388,0 +416,4 @@with pytest.raises(TypeError):await config.foo.inc(10)with pytest.raises(TypeError):await config.baz.inc(10)Done.
Anything left for me to do on this?
The only additional thing I'd request is on the subtraction/increment operators, allow a conditional to be passed for a minimum start/end value, which would raise an error and not commit the change.
This would allow some inlining of single access to those types while still keeping validation for the result.
The Mongo driver with these new methods is making 3 queries for each inc/toggle (except for one case). This is actually more than we would otherwise use for a simple get and set.
Because of the way we store data in mongo, the use of the
$incand$bitoperators isn't worth it. It would make more sense if each member/user/channel/guild etc.'s data included all defaults on initial set, but unfortunately that simply isn't the case.@ -154,0 +179,4 @@"""if isinstance(self.default, bool) or not isinstance(self.default, (int, float)):raise TypeError("Config inc method only supports integer or float values.")Might also want to say that the method only supports registered integer or float values
@ -154,0 +204,4 @@"""if not isinstance(self.default, bool):raise TypeError("Config toggle method can only toggle Boolean values.")Same here
The
Basedriver class should also be updated with these new methods. Mongo driver will be updated as necessary in #2536Superseded by #2635 due to the underlying driver changes and addition of MongoDBV2
Pull request closed