Use typing.Self throughout library

This commit is contained in:
Josh
2022-03-01 22:53:24 +10:00
committed by GitHub
parent a90e1824f4
commit 147948af9b
28 changed files with 212 additions and 191 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,