pycord icon indicating copy to clipboard operation
pycord copied to clipboard

feat: Implement better get_or_fetch

Open Lumabots opened this issue 8 months ago • 11 comments

Summary

Information

  • [ ] This PR fixes an issue.
  • [x] This PR adds something new (e.g. new method or parameters). #1856
  • [ ] 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

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

Lumabots avatar May 03 '25 20:05 Lumabots

feat from #1856

Lumabots avatar May 03 '25 20:05 Lumabots

still not ready have some bug like : NameError: name 'VoiceChannel' is not defined ig because of the type checking, i'll have to find a way to import it without circular import

Lumabots avatar May 03 '25 23:05 Lumabots

@Lumabots You can import it inside of the function where you use it directly instead of importing it at the top

Paillat-dev avatar May 03 '25 23:05 Paillat-dev

@Lumabots You can import it inside of the function where you use it directly instead of importing it at the top

Well ig the issue come from the definition for the typevar, so will that resolve it ?

Lumabots avatar May 03 '25 23:05 Lumabots

should be ready for review

Lumabots avatar May 04 '25 16:05 Lumabots

just need to specify that this is breaking inside the changelog cos of modification of get_or_fetch and removal of get_or_fetch_user

Lumabots avatar May 04 '25 16:05 Lumabots

ready for review

Lumabots avatar May 09 '25 05:05 Lumabots

Tests failed

plun1331 avatar May 09 '25 07:05 plun1331

@plun1331 concerning this review, this the shortcut from the guild and client has only some small change like member and user/guild, should i keep each doc different ? or should i just let that slide and so use utils.copy doc and import from utils the fetchable ?

Lumabots avatar May 09 '25 11:05 Lumabots

@plun1331 concerning this review, this the shortcut from the guild and client has only some small change like member and user/guild, should i keep each doc different ? or should i just let that slide and so use utils.copy doc and import from utils the fetchable ?

copy doc would work, but im realizing that get_or_fetch has an extra param that the wrapper methods don't, so maybe it would be better to write separate docs for all of them

and yes, still import the _FETCHABLE type from utils

plun1331 avatar May 09 '25 18:05 plun1331

maybe i could also handle in case the id is none by just retuning None, this could help as a helper fonction to not have to check with a if ... is not None, what are your thoughts ?

Lumabots avatar Jun 04 '25 16:06 Lumabots

Merge conflicts

Lulalaby avatar Aug 02 '25 03:08 Lulalaby

fixed

Lumabots avatar Aug 02 '25 10:08 Lumabots

Merge conflicts again 😂

Lulalaby avatar Aug 03 '25 03:08 Lulalaby

Maybe an unintended side-effect, Guild + AppEmoji is valid:

emoji = await utils.get_or_fetch(<Guild>, discord.AppEmoji, <valid guild emoji id>)
print(type(emoji)) # discord.GuildEmoji

Soheab avatar Oct 10 '25 22:10 Soheab

Tested and works, outside of the 2 comments above.

Soheab avatar Oct 10 '25 22:10 Soheab