disnake icon indicating copy to clipboard operation
disnake copied to clipboard

fix: type annotation for `View.add_item` method

Open fgfgdfgdfgfdgdf opened this issue 2 months ago • 4 comments

Summary

Fixes type annotation issue in View.add_item method where type checkers (Pylance/mypy) reported "Type of 'add_item' is partially unknown" due to missing generic parameter in Item annotation.

Checklist

  • [x] If code changes were made, then they have been tested
    • [x] I have updated the documentation to reflect the changes
    • [x] I have formatted the code properly by running uv run nox -s lint
    • [x] I have type-checked the code by running uv run nox -s pyright
  • [x] 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, ...)

fgfgdfgdfgfdgdf avatar Nov 05 '25 16:11 fgfgdfgdfgfdgdf

Documentation build overview

📚 disnake | 🛠️ Build #30212142 | 📁 Comparing 9dd5a8feb3f7a840f26cca20465c5cb3f88c512b against latest (0b119051760bb8a36f6ca8e2193fa294a5c02525)


🔍 Preview build

Show files changed (48 files in total): 📝 48 modified | ➕ 0 added | ➖ 0 deleted
File Status
index.html 📝 modified
whats_new.html 📝 modified
api/abc.html 📝 modified
api/activities.html 📝 modified
api/app_commands.html 📝 modified
api/app_info.html 📝 modified
api/audit_logs.html 📝 modified
api/automod.html 📝 modified
api/channels.html 📝 modified
api/clients.html 📝 modified
api/components.html 📝 modified
api/emoji.html 📝 modified
api/entitlements.html 📝 modified
api/events.html 📝 modified
api/exceptions.html 📝 modified
api/guild_scheduled_events.html 📝 modified
api/guilds.html 📝 modified
api/integrations.html 📝 modified
api/interactions.html 📝 modified
api/invites.html 📝 modified
api/localization.html 📝 modified
api/members.html 📝 modified
api/messages.html 📝 modified
api/misc.html 📝 modified
api/permissions.html 📝 modified
api/roles.html 📝 modified
api/skus.html 📝 modified
api/soundboard.html 📝 modified
api/stage_instances.html 📝 modified
api/stickers.html 📝 modified
api/subscriptions.html 📝 modified
api/ui.html 📝 modified
api/users.html 📝 modified
api/utilities.html 📝 modified
api/voice.html 📝 modified
api/webhooks.html 📝 modified
api/widgets.html 📝 modified
ext/tasks/index.html 📝 modified
ext/commands/api/app_commands.html 📝 modified
ext/commands/api/bots.html 📝 modified
ext/commands/api/checks.html 📝 modified
ext/commands/api/cogs.html 📝 modified
ext/commands/api/context.html 📝 modified
ext/commands/api/converters.html 📝 modified
ext/commands/api/exceptions.html 📝 modified
ext/commands/api/help_commands.html 📝 modified
ext/commands/api/misc.html 📝 modified
ext/commands/api/prefix_commands.html 📝 modified

Does this actually work for doing

view = View()
view.add_item(ui.Button())

? The components are currently typed to default to None on creation unless explicitly parametrized (ui.Button[View](...))

Enegg avatar Nov 05 '25 17:11 Enegg

Does this actually work for doing

view = View()
view.add_item(ui.Button())

? The components are currently typed to default to None on creation unless explicitly parametrized (ui.Button[View](...))

This doesn't work, and pylance gives me an error because the generic type of Item in the add_item method is unknown. If I specify Self or None, there will be no error

fgfgdfgdfgfdgdf avatar Nov 06 '25 03:11 fgfgdfgdfgfdgdf

pylance gives me an error because the generic type of Item in the add_item method is unknown.

I was asking specifically if this works after your fix, but it's clear now it is not as pyright in CI is failing. Item[Self] likely needs to become Item[Any].

Enegg avatar Nov 06 '25 14:11 Enegg