mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-07 10:22:59 +00:00
Use typing.Self throughout library
This commit is contained in:
@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Callable, Optional, TYPE_CHECKING, Tuple, Type, TypeVar, Union
|
||||
from typing import Callable, Optional, TYPE_CHECKING, Tuple, TypeVar, Union
|
||||
import inspect
|
||||
import os
|
||||
|
||||
@ -40,10 +40,11 @@ __all__ = (
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Self
|
||||
|
||||
from .view import View
|
||||
from ..emoji import Emoji
|
||||
|
||||
B = TypeVar('B', bound='Button')
|
||||
V = TypeVar('V', bound='View', covariant=True)
|
||||
|
||||
|
||||
@ -196,7 +197,7 @@ class Button(Item[V]):
|
||||
self._underlying.emoji = None
|
||||
|
||||
@classmethod
|
||||
def from_component(cls: Type[B], button: ButtonComponent) -> B:
|
||||
def from_component(cls, button: ButtonComponent) -> Self:
|
||||
return cls(
|
||||
style=button.style,
|
||||
label=button.label,
|
||||
|
@ -43,13 +43,14 @@ __all__ = (
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Self
|
||||
|
||||
from .view import View
|
||||
from ..types.components import SelectMenu as SelectMenuPayload
|
||||
from ..types.interactions import (
|
||||
MessageComponentInteractionData,
|
||||
)
|
||||
|
||||
S = TypeVar('S', bound='Select')
|
||||
V = TypeVar('V', bound='View', covariant=True)
|
||||
|
||||
|
||||
@ -272,7 +273,7 @@ class Select(Item[V]):
|
||||
self._selected_values = data.get('values', [])
|
||||
|
||||
@classmethod
|
||||
def from_component(cls: Type[S], component: SelectMenu) -> S:
|
||||
def from_component(cls, component: SelectMenu) -> Self:
|
||||
return cls(
|
||||
custom_id=component.custom_id,
|
||||
placeholder=component.placeholder,
|
||||
|
@ -25,7 +25,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from typing import TYPE_CHECKING, Optional, Tuple, Type, TypeVar
|
||||
from typing import TYPE_CHECKING, Optional, Tuple, TypeVar
|
||||
|
||||
from ..components import TextInput as TextInputComponent
|
||||
from ..enums import ComponentType, TextStyle
|
||||
@ -33,6 +33,8 @@ from ..utils import MISSING
|
||||
from .item import Item
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Self
|
||||
|
||||
from ..types.components import TextInput as TextInputPayload
|
||||
from ..types.interactions import ModalSubmitTextInputInteractionData as ModalSubmitTextInputInteractionDataPayload
|
||||
from .view import View
|
||||
@ -45,7 +47,6 @@ __all__ = (
|
||||
# fmt: on
|
||||
|
||||
V = TypeVar('V', bound='View', covariant=True)
|
||||
TI = TypeVar('TI', bound='TextInput')
|
||||
|
||||
|
||||
class TextInput(Item[V]):
|
||||
@ -210,7 +211,7 @@ class TextInput(Item[V]):
|
||||
self._value = data.get('value', None)
|
||||
|
||||
@classmethod
|
||||
def from_component(cls: Type[TI], component: TextInputComponent) -> TI:
|
||||
def from_component(cls, component: TextInputComponent) -> Self:
|
||||
return cls(
|
||||
label=component.label,
|
||||
style=component.style,
|
||||
|
Reference in New Issue
Block a user