Add public positive_int and finite_float converters #5969
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!5969
Loading…
Reference in a new issue
No description provided.
Delete branch "patch-7"
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?
Description of the changes
Hello,
This PR adds the
positive_intandfinite_floatconverters toredbot.core.commands.converter.Since
positive_intis an instance ofredbot.core.commands.Range, the appropriate error messages have been added tobot.on_command_errorwith typecommands.RangeError.Testing was done today in #testing the core server.
Thanks in advance and have a nice day,
AAA3A
Closes #5939
Have the changes in this PR been tested?
Yes
@ -684,9 +684,7 @@ class Cleanup(commands.Cog):@commands.guild_only()@commands.mod_or_permissions(manage_messages=True)You can remove the NewType import now as it is not used anywhere else in this file
There are a few changes needed for this PR which stood out to me, including part of the implementation which is missing. Could you address these changes, and then re-test them? I will also test them thoroughly when I review your changes again.
@ -5,3 +5,3 @@from importlib.machinery import ModuleSpecfrom pathlib import Pathfrom typing import TYPE_CHECKING, Union, List, Optionalfrom typing import Union, List, OptionalTYPE_CHECKINGis no longer used inside the cog_manager file, we can remove its import.@ -242,2 +240,4 @@if error.send_cmd_help:await ctx.send_help()elif isinstance(error, commands.RangeError):if isinstance(error.value, int):These strings should be changed for when the Range annotation is
str, because a "string no more than [...]" isn't grammatically fitting. I've made a suggestion but feel free to improvise if you have a better idea.Why are we doing this? It makes the response looks very absurd. Can the error value itself not be formatted here?

You haven't handled when the converter annotation is
strhere. That means the code will fall past this section and UnboundLocalError will be raised becausemessageisn't defined. You should add a condition here which accounts for when the converter annotation is a string. You should emulate the behaviour you defined above for when RangeError is raised. You should also take into account my grammatical comments I made above, and ensure that stays consistent in his handling of the converter error.I suggest using an else block here instead of an additional elif, as we only need to account for three types (str, float, int).
You can test these changes by creating a command which uses a
strannotation in the Range converter. For example:Currently, this raises an implicit error which looks like this:
Hello,
Thank you for your review of this PR.
All requested changes have been pushed.
Thanks in advance,
AAA3A
After #6002 was merged, to fix an error on the local clone of my Red fork, I force push the commits. I had forgotten to save the
redbot.core.commands.converterfile, so I lost it. I just made the changes again.You should update
redbot/core/commands/__init__.py, importing bothfinite_floatandpositive_intrespectively. You should also add these two converter names toredbot.core.commands.converter.__all__.Ah, I had thought of adding them to
redbot.core.commands, but I thought it was a bad idea. I'll do it tomorrow.There are still changes that are needed before this can be approved and merged. Have a look at the review comments, and test your changes afterwards if you can. Should be good to go if those changes are made correctly.
@ -241,10 +239,112 @@ def init_events(bot, cli_flags):await ctx.send(msg)Whilst this check makes sense, if the converter minimum were to be 1, and the user passes "0" to the converter, the message would still ask for a positive integer despite zero being a positive integer. Is the
== 1check really needed?Here, we check if the converter's max is None, so it will always read "no less than None", instead of our desired result. It just requires changing this part of the string in the suggestion.
Please apply the above comment to here aswell.
Whilst this check makes sense, if the minimum were to be 1, and "0" is passed to the converter, the message would still ask for a positive integer despite zero being a positive integer. Is the
== 1check really needed?Thanks for working on this, looks all set now 🎉