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

Adjust category and guild _channels attributes to work with NoneType positions #1530

Merged
merged 3 commits into from
Aug 5, 2022

Conversation

NeloBlivion
Copy link
Member

@NeloBlivion NeloBlivion commented Jul 28, 2022

Summary

Adapts guild/category _channels attributes (text_channels, voice_channels etc.) to work correctly with Optional positions.
Currently when grabbing a list of a guild's or a category's channels, the library attempts to sort them by position to output them in their UI order:

r.sort(key=lambda c: (c.position, c.id))

This worked fine when we just had TextChannel and VoiceChannel because position under abc.GuildChannel was required, but since 2.0 with new channel types and interaction payloads position has been made optional for all channel types; since position can now be None, this sort breaks with TypeError: '<' not supported between instances of 'NoneType' and 'int'.

The solution i've applied is to assume the channel's position is -1 if position = None, so it will order as much as possible; other solutions could be to try-except, completely give up on sorting, or to make -1 the default instead of None (achieving the same result, but perhaps with a knock-on effect elsewhere in the library).

I went with -1 since this was actually already present in Guild.by_category(), where it's assumed ID and position are -1 if it runs into a NoneType category. Alternatively, it could be a large number to assume the position is last instead of first.

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.

@Lulalaby Lulalaby added the bug Something isn't working label Jul 28, 2022
@Lulalaby Lulalaby enabled auto-merge (squash) July 28, 2022 16:53
Copy link
Member

@Dorukyum Dorukyum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for now

@Lulalaby Lulalaby merged commit a56d801 into Pycord-Development:master Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants