Skip to content

Conversation

Enegg
Copy link
Contributor

@Enegg Enegg commented Sep 15, 2025

Summary

Replaces bare # type: ignore comments with # pyright: ignore[specificRuleName, ...].
Disables support for # type: ignore by pyright; this results in pyright suggesting the full diagnostic name(s) for autofixes.
Some of the type ignores (mostly where type is None-able, but None isn't expected) have been replaced with asserts.
In a few places logic was fixed to avoid the comment entirely.

Checklist

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

@shiftinv shiftinv added t: refactor/typing/lint Refactors, typing changes and/or linting changes skip news labels Sep 15, 2025
self._retrieve_messages = self._retrieve_messages_around_strategy
if self.before and self.after:
self._filter = lambda m: self.after.id < int(m["id"]) < self.before.id # type: ignore
self._filter = lambda m: self.after.id < int(m["id"]) < self.before.id # pyright: ignore[reportOptionalMemberAccess]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These comments could be fixed by binding the narrowed self.before as a 2nd parameter to the lambda:

Suggested change
self._filter = lambda m: self.after.id < int(m["id"]) < self.before.id # pyright: ignore[reportOptionalMemberAccess]
self._filter = lambda m, b=self.before: self.after.id < int(m["id"]) < b.id

...but that changes parameter count, so idk

Copy link
Member

Choose a reason for hiding this comment

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

Submit a separate pull to fix these issues if you want to fix them.

disnake/poll.py Outdated
Comment on lines 386 to 388
"duration": int(self.duration.total_seconds()) // 3600
if self.duration is not None
else 24,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This technically changes the behavior (once discord adds non-expiring polls) but shrug
24 is the default duration

Copy link
Member

Choose a reason for hiding this comment

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

This should be proactive and not change the behaviour, as if the behaviour is changed it becomes a different outcome

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed it into an assert. Present code fails if it's None, so this should be a non-issue

@onerandomusername
Copy link
Member

Could you please resolve conflicts and enable ruff rule PGH003?

@Enegg Enegg changed the title feat(typing): replace # type: ignores with # pyright: ignore[ruleName] refactor(typing): replace # type: ignores with # pyright: ignore[ruleName] Sep 18, 2025
@Enegg Enegg changed the title refactor(typing): replace # type: ignores with # pyright: ignore[ruleName] refactor(typing): replace # type: ignores with # pyright: ignore[ruleName]; enable PGH003 Sep 21, 2025
Copy link

read-the-docs-community bot commented Sep 21, 2025

Documentation build overview

📚 disnake | 🛠️ Build #29820345 | 📁 Comparing af6b111 against latest (613e01d)


🔍 Preview build

Show files changed (50 files in total): 📝 50 modified | ➕ 0 added | ➖ 0 deleted
File Status
genindex.html 📝 modified
index.html 📝 modified
intro.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

Copy link
Member

@onerandomusername onerandomusername left a comment

Choose a reason for hiding this comment

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

I'd rather we didn't have any runtime changes in this pull, just typings.

"ANN0",
"ANN4",
## flake8-bandit
"S101", # use of assert is fine
Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely sold on this change: if run with opitmisations then the asserts will be gone

Copy link
Member

Choose a reason for hiding this comment

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

For shortcomings of Python's typing system I'd say asserts are fine, but for things that can actually happen (for instance, the API not returning values we'd expect, or incorrect usage of a method contrary to the docstring), an actual exception should be used, even if it's just raise AssertionError(...) so it can't be optimized away.

Copy link
Member

@Sharp-Eyes Sharp-Eyes Sep 23, 2025

Choose a reason for hiding this comment

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

Exactly this, asserts should only be used as an in-place alternative to typing.cast (where the lines being optimised out at runtime is actually beneficial), whereas any actual runtime exceptions should be raised. This matches Eneg's current implementation afaict at quick glance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe I've used asserts solely in places where the condition being false would result in the subsequent line failing.
For instance,

assert "foo" in typed_dict
typed_dict["foo"]

There are places where T | None is passed to something accepting just T, but since it doesn't fail (immediately, anyway) at runtime I've preserved the # type: ignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news t: refactor/typing/lint Refactors, typing changes and/or linting changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants