Skip to content

Commit

Permalink
Update pyright version
Browse files Browse the repository at this point in the history
  • Loading branch information
bijij authored Feb 20, 2024
1 parent 76666fb commit 4e03b17
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Run Pyright
uses: jakebailey/pyright-action@v1
with:
version: '1.1.316'
version: '1.1.351'
warnings: false
no-comments: ${{ matrix.python-version != '3.x' }}

Expand Down
2 changes: 1 addition & 1 deletion discord/app_commands/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def copy(self) -> Self:
:class:`Cooldown`
A new instance of this cooldown.
"""
return Cooldown(self.rate, self.per)
return self.__class__(self.rate, self.per)

def __repr__(self) -> str:
return f'<Cooldown rate: {self.rate} per: {self.per} window: {self._window} tokens: {self._tokens}>'
Expand Down
8 changes: 4 additions & 4 deletions discord/app_commands/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def __init__(self, *channel_types: Type[Any]) -> None:
except KeyError:
raise TypeError('Union type of channels must be entirely made up of channels') from None

self._types: Tuple[Type[Any]] = channel_types
self._types: Tuple[Type[Any], ...] = channel_types
self._channel_types: List[ChannelType] = types
self._display_name = display_name

Expand Down Expand Up @@ -780,19 +780,19 @@ def get_supported_annotation(
# Check if there's an origin
origin = getattr(annotation, '__origin__', None)
if origin is Literal:
args = annotation.__args__ # type: ignore
args = annotation.__args__
return (LiteralTransformer(args), MISSING, True)

if origin is Choice:
arg = annotation.__args__[0] # type: ignore
arg = annotation.__args__[0]
return (ChoiceTransformer(arg), MISSING, True)

if origin is not Union:
# Only Union/Optional is supported right now so bail early
raise TypeError(f'unsupported type annotation {annotation!r}')

default = MISSING
args = annotation.__args__ # type: ignore
args = annotation.__args__
if args[-1] is _none:
if len(args) == 2:
underlying = args[0]
Expand Down
6 changes: 3 additions & 3 deletions discord/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def replace(
url = url.with_query(url.raw_query_string)

url = str(url)
return Asset(state=self._state, url=url, key=self._key, animated=self._animated)
return self.__class__(state=self._state, url=url, key=self._key, animated=self._animated)

def with_size(self, size: int, /) -> Self:
"""Returns a new asset with the specified size.
Expand Down Expand Up @@ -457,7 +457,7 @@ def with_size(self, size: int, /) -> Self:
raise ValueError('size must be a power of 2 between 16 and 4096')

url = str(yarl.URL(self._url).with_query(size=size))
return Asset(state=self._state, url=url, key=self._key, animated=self._animated)
return self.__class__(state=self._state, url=url, key=self._key, animated=self._animated)

def with_format(self, format: ValidAssetFormatTypes, /) -> Self:
"""Returns a new asset with the specified format.
Expand Down Expand Up @@ -492,7 +492,7 @@ def with_format(self, format: ValidAssetFormatTypes, /) -> Self:
url = yarl.URL(self._url)
path, _ = os.path.splitext(url.path)
url = str(url.with_path(f'{path}.{format}').with_query(url.raw_query_string))
return Asset(state=self._state, url=url, key=self._key, animated=self._animated)
return self.__class__(state=self._state, url=url, key=self._key, animated=self._animated)

def with_static_format(self, format: ValidStaticFormatTypes, /) -> Self:
"""Returns a new asset with the specified static format.
Expand Down
2 changes: 1 addition & 1 deletion discord/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ async def edit(
**payload,
)

return AutoModRule(data=data, guild=self.guild, state=self._state)
return self.__class__(data=data, guild=self.guild, state=self._state)

async def delete(self, *, reason: str = MISSING) -> None:
"""|coro|
Expand Down
2 changes: 1 addition & 1 deletion discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ async def __aexit__(
def _get_websocket(self, guild_id: Optional[int] = None, *, shard_id: Optional[int] = None) -> DiscordWebSocket:
return self.ws

def _get_state(self, **options: Any) -> ConnectionState:
def _get_state(self, **options: Any) -> ConnectionState[Self]:
return ConnectionState(dispatch=self.dispatch, handlers=self._handlers, hooks=self._hooks, http=self.http, **options)

def _handle_ready(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion discord/colour.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def from_hsv(cls, h: float, s: float, v: float) -> Self:
return cls.from_rgb(*(int(x * 255) for x in rgb))

@classmethod
def from_str(cls, value: str) -> Self:
def from_str(cls, value: str) -> Colour:
"""Constructs a :class:`Colour` from a string.
The following formats are accepted:
Expand Down
12 changes: 8 additions & 4 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@
'EntitlementOwnerType',
)

if TYPE_CHECKING:
from typing_extensions import Self


def _create_value_cls(name: str, comparable: bool):
# All the type ignores here are due to the type checker being unable to recognise
Expand All @@ -104,7 +101,14 @@ class EnumMeta(type):
_enum_member_map_: ClassVar[Dict[str, Any]]
_enum_value_map_: ClassVar[Dict[Any, Any]]

def __new__(cls, name: str, bases: Tuple[type, ...], attrs: Dict[str, Any], *, comparable: bool = False) -> Self:
def __new__(
cls,
name: str,
bases: Tuple[type, ...],
attrs: Dict[str, Any],
*,
comparable: bool = False,
) -> EnumMeta:
value_mapping = {}
member_mapping = {}
member_names = []
Expand Down
4 changes: 2 additions & 2 deletions discord/ext/commands/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async def bar(self, ctx):
__cog_app_commands__: List[Union[app_commands.Group, app_commands.Command[Any, ..., Any]]]
__cog_listeners__: List[Tuple[str, str]]

def __new__(cls, *args: Any, **kwargs: Any) -> Self:
def __new__(cls, *args: Any, **kwargs: Any) -> CogMeta:
name, bases, attrs = args
if any(issubclass(base, app_commands.Group) for base in bases):
raise TypeError(
Expand Down Expand Up @@ -366,7 +366,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Self:
child.wrapped = lookup[child.qualified_name] # type: ignore

if self.__cog_app_commands_group__:
children.append(app_command) # type: ignore # Somehow it thinks it can be None here
children.append(app_command)

if Cog._get_overridden_method(self.cog_app_command_error) is not None:
error_handler = self.cog_app_command_error
Expand Down
2 changes: 1 addition & 1 deletion discord/ext/commands/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ def _convert_to_bool(argument: str) -> bool:
raise BadBoolArgument(lowered)


_GenericAlias = type(List[T])
_GenericAlias = type(List[T]) # type: ignore


def is_generic_type(tp: Any, *, _GenericAlias: type = _GenericAlias) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions discord/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def __init__(

# bandaid for the fact that sometimes parent can be the bot instance
parent: Optional[GroupMixin[Any]] = kwargs.get('parent')
self.parent: Optional[GroupMixin[Any]] = parent if isinstance(parent, _BaseCommand) else None # type: ignore # Does not recognise mixin usage
self.parent: Optional[GroupMixin[Any]] = parent if isinstance(parent, _BaseCommand) else None

self._before_invoke: Optional[Hook] = None
try:
Expand Down Expand Up @@ -776,7 +776,7 @@ def full_parent_name(self) -> str:
command = self
# command.parent is type-hinted as GroupMixin some attributes are resolved via MRO
while command.parent is not None: # type: ignore
command = command.parent
command = command.parent # type: ignore
entries.append(command.name) # type: ignore

return ' '.join(reversed(entries))
Expand All @@ -794,7 +794,7 @@ def parents(self) -> List[Group[Any, ..., Any]]:
entries = []
command = self
while command.parent is not None: # type: ignore
command = command.parent
command = command.parent # type: ignore
entries.append(command)

return entries
Expand Down
2 changes: 1 addition & 1 deletion discord/ext/commands/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def __new__(
case_insensitive: bool = MISSING,
delimiter: str = MISSING,
prefix: str = MISSING,
) -> Self:
) -> FlagsMeta:
attrs['__commands_is_flag__'] = True

try:
Expand Down
2 changes: 1 addition & 1 deletion discord/ext/commands/hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ def hybrid_command(
def decorator(func: CommandCallback[CogT, ContextT, P, T]) -> HybridCommand[CogT, P, T]:
if isinstance(func, Command):
raise TypeError('Callback is already a command.')
return HybridCommand(func, name=name, with_app_command=with_app_command, **attrs) # type: ignore # ???
return HybridCommand(func, name=name, with_app_command=with_app_command, **attrs)

return decorator

Expand Down
2 changes: 1 addition & 1 deletion discord/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(
else:
filename = getattr(fp, 'name', 'untitled')

self._filename, filename_spoiler = _strip_spoiler(filename)
self._filename, filename_spoiler = _strip_spoiler(filename) # type: ignore # pyright doesn't understand the above getattr
if spoiler is MISSING:
spoiler = filename_spoiler

Expand Down
16 changes: 8 additions & 8 deletions discord/ui/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
)

if TYPE_CHECKING:
from typing_extensions import TypeAlias, Self, TypeGuard
from typing_extensions import TypeAlias, TypeGuard

from .view import View
from ..types.components import SelectMenu as SelectMenuPayload
Expand Down Expand Up @@ -342,7 +342,7 @@ def is_dispatchable(self) -> bool:
return True

@classmethod
def from_component(cls, component: SelectMenu) -> Self:
def from_component(cls, component: SelectMenu) -> BaseSelect[V]:
type_to_cls: Dict[ComponentType, Type[BaseSelect[Any]]] = {
ComponentType.string_select: Select,
ComponentType.user_select: UserSelect,
Expand Down Expand Up @@ -887,7 +887,7 @@ def default_values(self, value: Sequence[ValidDefaultValues]) -> None:
@overload
def select(
*,
cls: Type[SelectT] = Select[V],
cls: Type[SelectT] = Select[Any],
options: List[SelectOption] = MISSING,
channel_types: List[ChannelType] = ...,
placeholder: Optional[str] = ...,
Expand All @@ -903,7 +903,7 @@ def select(
@overload
def select(
*,
cls: Type[UserSelectT] = UserSelect[V],
cls: Type[UserSelectT] = UserSelect[Any],
options: List[SelectOption] = MISSING,
channel_types: List[ChannelType] = ...,
placeholder: Optional[str] = ...,
Expand All @@ -920,7 +920,7 @@ def select(
@overload
def select(
*,
cls: Type[RoleSelectT] = RoleSelect[V],
cls: Type[RoleSelectT] = RoleSelect[Any],
options: List[SelectOption] = MISSING,
channel_types: List[ChannelType] = ...,
placeholder: Optional[str] = ...,
Expand All @@ -937,7 +937,7 @@ def select(
@overload
def select(
*,
cls: Type[ChannelSelectT] = ChannelSelect[V],
cls: Type[ChannelSelectT] = ChannelSelect[Any],
options: List[SelectOption] = MISSING,
channel_types: List[ChannelType] = ...,
placeholder: Optional[str] = ...,
Expand All @@ -954,7 +954,7 @@ def select(
@overload
def select(
*,
cls: Type[MentionableSelectT] = MentionableSelect[V],
cls: Type[MentionableSelectT] = MentionableSelect[Any],
options: List[SelectOption] = MISSING,
channel_types: List[ChannelType] = MISSING,
placeholder: Optional[str] = ...,
Expand All @@ -970,7 +970,7 @@ def select(

def select(
*,
cls: Type[BaseSelectT] = Select[V],
cls: Type[BaseSelectT] = Select[Any],
options: List[SelectOption] = MISSING,
channel_types: List[ChannelType] = MISSING,
placeholder: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion discord/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ async def sane_wait_for(futures: Iterable[Awaitable[T]], *, timeout: Optional[fl
def get_slots(cls: Type[Any]) -> Iterator[str]:
for mro in reversed(cls.__mro__):
try:
yield from mro.__slots__ # type: ignore
yield from mro.__slots__
except AttributeError:
continue

Expand Down
2 changes: 1 addition & 1 deletion discord/welcome_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,4 @@ async def edit(
fields['enabled'] = enabled

data = await self._state.http.edit_welcome_screen(self._guild.id, reason=reason, **fields)
return WelcomeScreen(data=data, guild=self._guild)
return self.__class__(data=data, guild=self._guild)

0 comments on commit 4e03b17

Please sign in to comment.