-
Couldn't load subscription status.
- Fork 145
style: enable more pyright rules #1441
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Enable `reportInconsistentOverload` and `reportInvalidTypeVarUse` pyright rules. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,13 +32,21 @@ | |||||
|
|
||||||
|
|
||||||
| T = TypeVar("T") | ||||||
| BotT = TypeVar("BotT", bound="Union[Bot, AutoShardedBot]") | ||||||
| CogT = TypeVar("CogT", bound="Cog") | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
| from typing_extensions import TypeVar # noqa: TC004 | ||||||
|
|
||||||
| P = ParamSpec("P") | ||||||
| BotT = TypeVar( | ||||||
| "BotT", | ||||||
| bound="Union[Bot, AutoShardedBot]", | ||||||
| covariant=True, | ||||||
| default=Union[Bot, AutoShardedBot], | ||||||
| ) | ||||||
| else: | ||||||
| P = TypeVar("P") | ||||||
| BotT = TypeVar("BotT", bound="Union[Bot, AutoShardedBot]") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no real need to specify anything but the TypeVar's name in the
Suggested change
|
||||||
|
|
||||||
|
|
||||||
| class Context(disnake.abc.Messageable, Generic[BotT]): | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -97,25 +97,30 @@ | |||||||||
|
|
||||||||||
| MISSING: Any = disnake.utils.MISSING | ||||||||||
|
|
||||||||||
| T = TypeVar("T") | ||||||||||
| VT = TypeVar("VT") | ||||||||||
| CogT = TypeVar("CogT", bound="Optional[Cog]") | ||||||||||
| CommandT = TypeVar("CommandT", bound="Command") | ||||||||||
| ContextT = TypeVar("ContextT", bound="Context") | ||||||||||
| GroupT = TypeVar("GroupT", bound="Group") | ||||||||||
| HookT = TypeVar("HookT", bound="Hook") | ||||||||||
| ErrorT = TypeVar("ErrorT", bound="Error") | ||||||||||
|
|
||||||||||
|
|
||||||||||
| if TYPE_CHECKING: | ||||||||||
| P = ParamSpec("P") | ||||||||||
| from typing_extensions import TypeVar # noqa: TC004 | ||||||||||
|
|
||||||||||
| P = ParamSpec("P", default=...) | ||||||||||
| T = TypeVar("T", default=Any) | ||||||||||
|
|
||||||||||
| CogT = TypeVar("CogT", bound="Optional[Cog]", default="Optional[Cog]") | ||||||||||
| ContextT = TypeVar("ContextT", bound="Context", default="Context") | ||||||||||
| CommandCallback = Union[ | ||||||||||
| Callable[Concatenate[CogT, ContextT, P], Coro[T]], | ||||||||||
| Callable[Concatenate[ContextT, P], Coro[T]], | ||||||||||
| ] | ||||||||||
| else: | ||||||||||
| T = TypeVar("T") | ||||||||||
| P = TypeVar("P") | ||||||||||
| CogT = TypeVar("CogT", bound="Optional[Cog]") | ||||||||||
| ContextT = TypeVar("ContextT", bound="Context") | ||||||||||
|
Comment on lines
+122
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/DisnakeDev/disnake/pull/1441/files#r2443495659
Suggested change
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| def wrap_callback(coro: Callable[..., Coro[T]]) -> Callable[..., Coro[Optional[T]]]: | ||||||||||
|
|
@@ -1418,7 +1423,7 @@ def copy(self: GroupT) -> GroupT: | |||||||||
| """ | ||||||||||
| ret = super().copy() | ||||||||||
| for cmd in self.commands: | ||||||||||
| ret.add_command(cmd.copy()) | ||||||||||
| ret.add_command(cast("Command[CogT, Any, Any]", cmd.copy())) | ||||||||||
| return ret | ||||||||||
|
|
||||||||||
| async def invoke(self, ctx: Context) -> None: | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,10 @@ | |||||
| from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
| from typing_extensions import TypeAlias | ||||||
| from typing_extensions import ( | ||||||
| TypeAlias, | ||||||
| TypeVar, # noqa: TC004 | ||||||
| ) | ||||||
|
|
||||||
| from . import ( | ||||||
| ActionRow, | ||||||
|
|
@@ -24,7 +27,9 @@ | |||||
| from .select import ChannelSelect, MentionableSelect, RoleSelect, StringSelect, UserSelect | ||||||
| from .view import View | ||||||
|
|
||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True) | ||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True, default=Optional[View]) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/DisnakeDev/disnake/pull/1441/files#r2443498907
Suggested change
|
||||||
| else: | ||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/DisnakeDev/disnake/pull/1441/files#r2443495659
Suggested change
|
||||||
|
|
||||||
| AnySelect = Union[ | ||||||
| "ChannelSelect[V_co]", | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,18 +17,23 @@ | |||||
| ) | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
| from typing_extensions import ParamSpec, Self | ||||||
| from typing_extensions import ( | ||||||
| ParamSpec, | ||||||
| Self, | ||||||
| TypeVar, # noqa: TC004 | ||||||
| ) | ||||||
|
|
||||||
| from ..emoji import Emoji | ||||||
| from .item import ItemCallbackType | ||||||
| from .view import View | ||||||
|
|
||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True, default=Optional[View]) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/DisnakeDev/disnake/pull/1441/files#r2443498907
Suggested change
|
||||||
| else: | ||||||
| ParamSpec = TypeVar | ||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| B = TypeVar("B", bound="Button") | ||||||
| B_co = TypeVar("B_co", bound="Button", covariant=True) | ||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True) | ||||||
| P = ParamSpec("P") | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -83,36 +88,6 @@ class Button(Item[V_co]): | |||||
| # We have to set this to MISSING in order to overwrite the abstract property from UIComponent | ||||||
| _underlying: ButtonComponent = MISSING | ||||||
|
|
||||||
| @overload | ||||||
| def __init__( | ||||||
| self: Button[None], | ||||||
| *, | ||||||
| style: ButtonStyle = ButtonStyle.secondary, | ||||||
| label: Optional[str] = None, | ||||||
| disabled: bool = False, | ||||||
| custom_id: Optional[str] = None, | ||||||
| url: Optional[str] = None, | ||||||
| emoji: Optional[Union[str, Emoji, PartialEmoji]] = None, | ||||||
| sku_id: Optional[int] = None, | ||||||
| id: int = 0, | ||||||
| row: Optional[int] = None, | ||||||
| ) -> None: ... | ||||||
|
|
||||||
| @overload | ||||||
| def __init__( | ||||||
| self: Button[V_co], | ||||||
| *, | ||||||
| style: ButtonStyle = ButtonStyle.secondary, | ||||||
| label: Optional[str] = None, | ||||||
| disabled: bool = False, | ||||||
| custom_id: Optional[str] = None, | ||||||
| url: Optional[str] = None, | ||||||
| emoji: Optional[Union[str, Emoji, PartialEmoji]] = None, | ||||||
| sku_id: Optional[int] = None, | ||||||
| id: int = 0, | ||||||
| row: Optional[int] = None, | ||||||
| ) -> None: ... | ||||||
|
|
||||||
| def __init__( | ||||||
| self, | ||||||
| *, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,11 +22,12 @@ | |||||||||||||||||
| "Item", | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| I = TypeVar("I", bound="Item[Any]") # noqa: E741 | ||||||||||||||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True) | ||||||||||||||||||
|
|
||||||||||||||||||
| if TYPE_CHECKING: | ||||||||||||||||||
| from typing_extensions import Self | ||||||||||||||||||
| from typing_extensions import ( | ||||||||||||||||||
| Self, | ||||||||||||||||||
| TypeVar, # noqa: TC004 | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| from ..client import Client | ||||||||||||||||||
| from ..components import ActionRowChildComponent, Component | ||||||||||||||||||
|
|
@@ -35,8 +36,18 @@ | |||||||||||||||||
| from ..types.components import ActionRowChildComponent as ActionRowChildComponentPayload | ||||||||||||||||||
| from .view import View | ||||||||||||||||||
|
|
||||||||||||||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True, default=Optional[View]) | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| I = TypeVar("I", bound="Item[Any]", default="Item[Any]") # noqa: E741 | ||||||||||||||||||
| ItemCallbackType = Callable[[V_co, I, MessageInteraction], Coroutine[Any, Any, Any]] | ||||||||||||||||||
|
|
||||||||||||||||||
| SelfViewT = TypeVar("SelfViewT", bound="Optional[View]", default=Optional[View]) | ||||||||||||||||||
| else: | ||||||||||||||||||
| I = TypeVar("I", bound="Item[Any]") # noqa: E741 | ||||||||||||||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True) | ||||||||||||||||||
|
|
||||||||||||||||||
| SelfViewT = TypeVar("SelfViewT", bound="Optional[View]") | ||||||||||||||||||
|
Comment on lines
+45
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| ClientT = TypeVar("ClientT", bound="Client") | ||||||||||||||||||
| UIComponentT = TypeVar("UIComponentT", bound="UIComponent") | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -159,12 +170,6 @@ class Item(WrappedComponent, Generic[V_co]): | |||||||||||||||||
|
|
||||||||||||||||||
| __repr_attributes__: ClassVar[tuple[str, ...]] = ("row",) | ||||||||||||||||||
|
|
||||||||||||||||||
| @overload | ||||||||||||||||||
| def __init__(self: Item[None]) -> None: ... | ||||||||||||||||||
|
|
||||||||||||||||||
| @overload | ||||||||||||||||||
| def __init__(self: Item[V_co]) -> None: ... | ||||||||||||||||||
|
|
||||||||||||||||||
| def __init__(self) -> None: | ||||||||||||||||||
| self._view: V_co = None # pyright: ignore[reportAttributeAccessIssue] | ||||||||||||||||||
| self._row: Optional[int] = None | ||||||||||||||||||
|
|
@@ -223,9 +228,6 @@ async def callback(self, interaction: MessageInteraction[ClientT], /) -> None: | |||||||||||||||||
| pass | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| SelfViewT = TypeVar("SelfViewT", bound="Optional[View]") | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| # While the decorators don't actually return a descriptor that matches this protocol, | ||||||||||||||||||
| # this protocol ensures that type checkers don't complain about statements like `self.button.disabled = True`, | ||||||||||||||||||
| # which work as `View.__init__` replaces the handler with the item. | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -24,19 +24,24 @@ | |||||
| __all__ = ("BaseSelect",) | ||||||
|
|
||||||
| if TYPE_CHECKING: | ||||||
| from typing_extensions import ParamSpec, Self | ||||||
| from typing_extensions import ( | ||||||
| ParamSpec, | ||||||
| Self, | ||||||
| TypeVar, # noqa: TC004 | ||||||
| ) | ||||||
|
|
||||||
| from ...abc import Snowflake | ||||||
| from ...interactions import MessageInteraction | ||||||
| from ..item import ItemCallbackType | ||||||
| from ..view import View | ||||||
|
|
||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True, default=Optional[View]) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current behavior is to default to
Suggested change
|
||||||
| else: | ||||||
| ParamSpec = TypeVar | ||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/DisnakeDev/disnake/pull/1441/files#r2443495659
Suggested change
|
||||||
|
|
||||||
|
|
||||||
| S_co = TypeVar("S_co", bound="BaseSelect", covariant=True) | ||||||
| V_co = TypeVar("V_co", bound="Optional[View]", covariant=True) | ||||||
| SelectMenuT = TypeVar("SelectMenuT", bound=AnySelectMenu) | ||||||
| SelectValueT = TypeVar("SelectValueT") | ||||||
| P = ParamSpec("P") | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,38 +109,6 @@ class ChannelSelect(BaseSelect[ChannelSelectMenu, "AnyChannel", V_co]): | |
| ), | ||
| } | ||
|
|
||
| @overload | ||
| def __init__( | ||
| self: ChannelSelect[None], | ||
| *, | ||
| custom_id: str = ..., | ||
| placeholder: Optional[str] = None, | ||
| min_values: int = 1, | ||
| max_values: int = 1, | ||
| disabled: bool = False, | ||
| channel_types: Optional[list[ChannelType]] = None, | ||
| default_values: Optional[Sequence[SelectDefaultValueInputType[AnyChannel]]] = None, | ||
| required: bool = True, | ||
| id: int = 0, | ||
| row: Optional[int] = None, | ||
| ) -> None: ... | ||
|
|
||
| @overload | ||
| def __init__( | ||
| self: ChannelSelect[V_co], | ||
| *, | ||
| custom_id: str = ..., | ||
| placeholder: Optional[str] = None, | ||
| min_values: int = 1, | ||
| max_values: int = 1, | ||
| disabled: bool = False, | ||
| channel_types: Optional[list[ChannelType]] = None, | ||
| default_values: Optional[Sequence[SelectDefaultValueInputType[AnyChannel]]] = None, | ||
| required: bool = True, | ||
| id: int = 0, | ||
| row: Optional[int] = None, | ||
| ) -> None: ... | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing those should only be done once There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Going to try to convert as many of these as I can to have a default. Moving this to draft for now. Will return to this PR later. |
||
| def __init__( | ||
| self, | ||
| *, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be
EnumMetaT, before you rebased the TypeVar was incorrectly bound totype[EnumMeta]