Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext.commands): required is False although default is None #2282

Merged
merged 3 commits into from
Dec 14, 2023

Conversation

solaluset
Copy link
Contributor

Summary

#2089 (comment)

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

@Dorukyum
Copy link
Member

Dorukyum commented Dec 9, 2023

I don't understand, there's no way x or y returns False when one side is True

@Lulalaby
Copy link
Member

Lulalaby commented Dec 9, 2023

Yeah same thought here. Closing it as invalid.

@solaluset
Copy link
Contributor Author

solaluset commented Dec 9, 2023

@Lulalaby @Dorukyum is this code valid?

@bot.bridge_command()
async def test_no_default(ctx, text: Option(str, required=False)):
    await ctx.respond(text or "hello")

I think it should work but it doesn't because the default is None.

UPDATE: BTW, it works as a slash command, but not as prefix command. Hence the inconsistency.

@plun1331
Copy link
Member

plun1331 commented Dec 9, 2023

I don't understand, there's no way x or y returns False when one side is True

The issue seems to be that it's returning True when it logically shouldn't (required is False, however default is None)

default being None should not change the behavior of required

@Dorukyum
Copy link
Member

default being None should not change the behavior of required

Isn't that how it's always been? Option(...) would be required while Option(..., default=None) would be optional.

@solaluset
Copy link
Contributor Author

default being None should not change the behavior of required

Isn't that how it's always been? Option(...) would be required while Option(..., default=None) would be optional.

Yes, but it didn't (and still doesn't) work for bridge commands invoked via prefix.

This PR fixes the issue.

@plun1331
Copy link
Member

plun1331 commented Dec 10, 2023

default being None should not change the behavior of required

Isn't that how it's always been? Option(...) would be required while Option(..., default=None) would be optional.

But if required is False with default being None, it automatically flips required to True (at least, that's my understanding of this pr)

@solaluset
Copy link
Contributor Author

solaluset commented Dec 10, 2023

But if required is False with default being None, it automatically flips required to True (at least, that's my understanding of this pr)

Yes. Because of this the command above doesn't work without the argument.
The most confusing part is that it works when invoked as a slash command.

By the way, looks like Option already sets its .required attribute properly. Maybe it should be just required = param.annotation.required.

@solaluset
Copy link
Contributor Author

Missclick 😅

@Dorukyum
Copy link
Member

By the way, looks like Option already sets its .required attribute properly. Maybe it should be just required = param.annotation.required.

My bad, I understand the pr now and I think you're right. We can't do and default is None because default doesn't have to be None. Like you said, Option already sets required meaning we can just use required = param.annotation.required here.

discord/ext/commands/core.py Outdated Show resolved Hide resolved
@Dorukyum Dorukyum changed the title fix(ext.commands): Fixed required=False when default is None fix(ext.commands): required is False although default is None Dec 11, 2023
@Dorukyum Dorukyum enabled auto-merge (squash) December 11, 2023 10:21
@Dorukyum Dorukyum requested a review from plun1331 December 11, 2023 10:22
@Dorukyum Dorukyum merged commit ca9700f into Pycord-Development:master Dec 14, 2023
26 checks passed
@solaluset solaluset deleted the bridge-default-fix branch December 15, 2023 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants