disnake icon indicating copy to clipboard operation
disnake copied to clipboard

feat(client)!: Make kwargs for 'public api' Client classes explicit, disallow superfluous kwargs

Open Sharp-Eyes opened this issue 3 years ago • 10 comments

Summary

This PR aims to improve two things. Firstly, passing 'incorrect'/unused kwargs to Client or any of its subclasses will now error. For example,

bot = commands.Bot("!", sync_command_debug=True)

would run fine in the current version of disnake but do nothing, as the actual kwarg is sync_commands_debug. With the changes in this PR, this would raise an error instead.

Furthermore, disnake.Client, disnake.AutoShardedClient, disnake.Bot, dinake.AutoShardedBot, disnake.InteractionBot and disnake.AutoShardedInteractionBot now all have their __init__s set in such a way that all possible kwargs display (unless I missed any, though I don't believe I did).

Checklist

  • [x] If code changes were made, then they have been tested
    • [ ] I have updated the documentation to reflect the changes
    • [x] I have formatted the code properly by running task lint or pre-commit run --all-files
  • [x] This PR fixes an issue
  • [ ] This PR adds something new (e.g. new method or parameters)
  • [x] This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • [ ] This PR is not a code change (e.g. documentation, README, ...)

Sharp-Eyes avatar Feb 21 '22 21:02 Sharp-Eyes

A possible future improvement could also be removing **kwargs from Client._get_state, but that's somewhat out of scope for this PR as it wouldn't affect the public interface at all

shiftinv avatar Mar 09 '22 16:03 shiftinv

That should be all (for now), fingers crossed ^^

Sharp-Eyes avatar Mar 25 '22 00:03 Sharp-Eyes

@Chromosomologist could you please update this pull with the newest options?

onerandomusername avatar Jun 06 '22 00:06 onerandomusername

Alright, merging and updating with new params should be done, but I haven't had time to test yet.

Sharp-Eyes avatar Jun 07 '22 19:06 Sharp-Eyes

hi @Chromosomologist, would you please update this pull?

onerandomusername avatar Jul 05 '22 18:07 onerandomusername

I do like the changes this pr makes, but I am curious about keeping **kwargs and an argument, allow_extraneous_arguments which if False, (the default) raises TypeError about unexpected arguments. However, if this True, a warning is emitted that an extra argument was provided and nothing else occurs

Sounds like a decent idea, yeah. I'll try to get this added, too.

Sharp-Eyes avatar Jul 05 '22 21:07 Sharp-Eyes

Explicit kwargs for CommonBotBase and the requested allow_extraneous_arguments arg are still to-do; that should be all.

Sharp-Eyes avatar Jul 17 '22 21:07 Sharp-Eyes

I do like the changes this pr makes, but I am curious about keeping **kwargs and an argument, allow_extraneous_arguments which if False, (the default) raises TypeError about unexpected arguments. However, if this True, a warning is emitted that an extra argument was provided and nothing else occurs

This is not required but would be nice for people updating IMO.

Not sure if I understand the purpose of this 🤔 If you were to update, you'd need to modify your code regardless, either fixing the extra args, or adding that allow_extraneous_arguments argument. Is there any practical reason to allow passing extra args?

shiftinv avatar Jul 18 '22 08:07 shiftinv

Not sure if I understand the purpose of this 🤔 If you were to update, you'd need to modify your code regardless, either fixing the extra args, or adding that allow_extraneous_arguments argument. Is there any practical reason to allow passing extra args?

True, since it'd require a code change either way it's somewhat nonsensical.

Either way, the PR should be done now, changes-wise (assuming we agree on not adding the allow_extraneous_arguments argument). It does still need some amount of testing, though I may not have enough time to properly do so before I leave.

Sharp-Eyes avatar Jul 22 '22 20:07 Sharp-Eyes

(assuming we agree on not adding the allow_extraneous_arguments argument)

Yeah, it makes sense to not add this, as this would lead to bugs and doesn't make much sense in end-user code for purposes that aren't what I'm doing.

onerandomusername avatar Jul 24 '22 08:07 onerandomusername

@Chromosomologist would you please address the reviews on this pr?

onerandomusername avatar Aug 13 '22 03:08 onerandomusername

Now that extra parameters result in errors, the warning about the sync_permissions parameter can be removed, which then also correctly results in an error if provided: https://github.com/DisnakeDev/disnake/blob/4c17fdc45a88dffd215db6b824c8f3e88dfe81b3/disnake/ext/commands/interaction_bot_base.py#L157-L158

I'm pretty sure this is the final change I'd propose in this PR, it's been going on for long enough at this point :p The only remaining discussion is about MISSING and None, haven't really kept up with it so perhaps you already came to a conclusion there.

shiftinv avatar Aug 25 '22 12:08 shiftinv

There already is some prior ordering into different categories (see this discussion); whether that's better or worse than alphabetizing them, I am not really sure.

Sharp-Eyes avatar Sep 05 '22 19:09 Sharp-Eyes

I think we should have parameters ordered alphabetically but other than that, should be good to go

@shiftinv is this worth putting in a second pr instead of here, as I think it might be.

onerandomusername avatar Sep 06 '22 19:09 onerandomusername

is this worth putting in a second pr instead of here

Would be better in a second PR, but I wouldn't mind if it was added in this one :shrug:

shiftinv avatar Sep 06 '22 19:09 shiftinv