diff --git a/disnake/abc.py b/disnake/abc.py index 245a6ff10d..45b076c19f 100644 --- a/disnake/abc.py +++ b/disnake/abc.py @@ -480,6 +480,7 @@ async def _edit( if options: return await self._state.http.edit_channel(self.id, reason=reason, **options) + return None def _fill_overwrites(self, data: GuildChannelPayload) -> None: self._overwrites = [] diff --git a/disnake/activity.py b/disnake/activity.py index b66fe5d129..7914e81814 100644 --- a/disnake/activity.py +++ b/disnake/activity.py @@ -103,6 +103,7 @@ def created_at(self) -> Optional[datetime.datetime]: return datetime.datetime.fromtimestamp( self._created_at / 1000, tz=datetime.timezone.utc ) + return None @property def start(self) -> Optional[datetime.datetime]: diff --git a/disnake/audit_logs.py b/disnake/audit_logs.py index cd3384bbc9..3a2154b101 100644 --- a/disnake/audit_logs.py +++ b/disnake/audit_logs.py @@ -380,7 +380,7 @@ def __init__(self, entry: AuditLogEntry, data: List[AuditLogChangePayload]) -> N if attr == "$add": self._handle_role(self.before, self.after, entry, elem["new_value"]) # type: ignore continue - elif attr == "$remove": + if attr == "$remove": self._handle_role(self.after, self.before, entry, elem["new_value"]) # type: ignore continue diff --git a/disnake/channel.py b/disnake/channel.py index 99c5ee3d89..642d73bb4f 100644 --- a/disnake/channel.py +++ b/disnake/channel.py @@ -548,6 +548,7 @@ async def edit( if payload is not None: # the payload will always be the proper channel payload return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore + return None async def clone( self, @@ -1711,6 +1712,7 @@ async def edit( if payload is not None: # the payload will always be the proper channel payload return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore + return None async def delete_messages(self, messages: Iterable[Snowflake]) -> None: """|coro| @@ -2568,6 +2570,7 @@ async def edit( if payload is not None: # the payload will always be the proper channel payload return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore + return None async def delete_messages(self, messages: Iterable[Snowflake]) -> None: """|coro| @@ -3060,6 +3063,7 @@ async def edit( if payload is not None: # the payload will always be the proper channel payload return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore + return None @overload async def move( @@ -4223,6 +4227,7 @@ async def edit( if payload is not None: # the payload will always be the proper channel payload return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore + return None async def clone( self, @@ -4621,6 +4626,7 @@ async def edit( if payload is not None: # the payload will always be the proper channel payload return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore + return None async def clone( self, diff --git a/disnake/client.py b/disnake/client.py index 653d2c0bbb..bf39cbdced 100644 --- a/disnake/client.py +++ b/disnake/client.py @@ -1317,10 +1317,11 @@ def stop_loop_on_completion(f) -> None: if not future.cancelled(): try: - return future.result() + future.result() except KeyboardInterrupt: # I am unsure why this gets raised here but suppress it anyway - return None + pass + return # properties @@ -1458,6 +1459,7 @@ def get_stage_instance(self, id: int, /) -> Optional[StageInstance]: if isinstance(channel, StageChannel): return channel.instance + return None def get_guild(self, id: int, /) -> Optional[Guild]: """Returns a guild with the given ID. diff --git a/disnake/embeds.py b/disnake/embeds.py index eb91c25bfb..8a064df468 100644 --- a/disnake/embeds.py +++ b/disnake/embeds.py @@ -36,7 +36,7 @@ def __getattr__(name: str) -> None: "`EmptyEmbed` is deprecated and will be removed in a future version. Use `None` instead.", stacklevel=2, ) - return None + return None # noqa: RET501 msg = f"module '{__name__}' has no attribute '{name}'" raise AttributeError(msg) @@ -233,7 +233,7 @@ def Empty(self) -> None: "`Embed.Empty` is deprecated and will be removed in a future version. Use `None` instead.", stacklevel=3, ) - return None + return None # noqa: RET501 @classmethod def from_dict(cls, data: EmbedData) -> Self: diff --git a/disnake/emoji.py b/disnake/emoji.py index 57c6c113d7..c1f126870b 100644 --- a/disnake/emoji.py +++ b/disnake/emoji.py @@ -253,18 +253,18 @@ async def delete(self, *, reason: Optional[str] = None) -> None: InvalidData The emoji data is invalid and cannot be processed. """ - if self.guild_id is None: - # this is an app emoji - if self.application_id is None: - # should never happen - msg = ( - f"guild_id and application_id are both None when attempting to delete emoji with ID {self.id}." - " This may be a library bug! Open an issue on GitHub." - ) - raise InvalidData(msg) - - return await self._state.http.delete_app_emoji(self.application_id, self.id) - await self._state.http.delete_custom_emoji(self.guild_id, self.id, reason=reason) + if self.guild_id is not None: + await self._state.http.delete_custom_emoji(self.guild_id, self.id, reason=reason) + return + if self.application_id is not None: + await self._state.http.delete_app_emoji(self.application_id, self.id) + return + # should never happen + msg = ( + f"guild_id and application_id are both None when attempting to delete emoji with ID {self.id}." + " This may be a library bug! Open an issue on GitHub." + ) + raise InvalidData(msg) async def edit( self, *, name: str = MISSING, roles: List[Snowflake] = MISSING, reason: Optional[str] = None diff --git a/disnake/ext/commands/base_core.py b/disnake/ext/commands/base_core.py index fdd543df51..3fc0fab7cb 100644 --- a/disnake/ext/commands/base_core.py +++ b/disnake/ext/commands/base_core.py @@ -84,7 +84,7 @@ async def wrapped(*args, **kwargs): except CommandError: raise except asyncio.CancelledError: - return + return None except Exception as exc: raise CommandInvokeError(exc) from exc return ret @@ -507,7 +507,7 @@ async def _call_local_error_handler( self, inter: ApplicationCommandInteraction, error: CommandError ) -> Any: if not self.has_error_handler(): - return + return None injected = wrap_callback(self.on_error) if self.cog is not None: diff --git a/disnake/ext/commands/bot_base.py b/disnake/ext/commands/bot_base.py index ea78e35710..8520fbcd2f 100644 --- a/disnake/ext/commands/bot_base.py +++ b/disnake/ext/commands/bot_base.py @@ -86,8 +86,7 @@ async def get_prefix(bot, message): def inner(bot: BotBase, msg: Message) -> List[str]: r = list(prefixes) - r = when_mentioned(bot, msg) + r - return r + return when_mentioned(bot, msg) + r return inner diff --git a/disnake/ext/commands/common_bot_base.py b/disnake/ext/commands/common_bot_base.py index ea4f06e6f6..3241e82277 100644 --- a/disnake/ext/commands/common_bot_base.py +++ b/disnake/ext/commands/common_bot_base.py @@ -249,7 +249,7 @@ def remove_cog(self, name: str) -> Optional[Cog]: """ cog = self.__cogs.pop(name, None) if cog is None: - return + return None help_command: Optional[HelpCommand] = getattr(self, "_help_command", None) if help_command and help_command.cog is cog: diff --git a/disnake/ext/commands/cooldowns.py b/disnake/ext/commands/cooldowns.py index 8b28182d48..7b3dcea64c 100644 --- a/disnake/ext/commands/cooldowns.py +++ b/disnake/ext/commands/cooldowns.py @@ -64,6 +64,7 @@ def get_key(self, msg: Message) -> Any: return ( msg.author.top_role if msg.guild and isinstance(msg.author, Member) else msg.channel ).id + return None def __call__(self, msg: Message) -> Any: return self.get_key(msg) @@ -163,6 +164,7 @@ def update_rate_limit(self, current: Optional[float] = None) -> Optional[float]: # we're not so decrement our tokens self._tokens -= 1 + return None def reset(self) -> None: """Reset the cooldown to its initial state.""" diff --git a/disnake/ext/commands/core.py b/disnake/ext/commands/core.py index e2defd9197..b04e5efbae 100644 --- a/disnake/ext/commands/core.py +++ b/disnake/ext/commands/core.py @@ -1038,8 +1038,7 @@ def signature(self) -> str: else f"[{name}={param.default}]..." ) continue - else: - result.append(f"[{name}]") + result.append(f"[{name}]") elif param.kind == param.VAR_POSITIONAL: if self.require_var_positional: diff --git a/disnake/ext/commands/help.py b/disnake/ext/commands/help.py index 876c7478da..dda98cc872 100644 --- a/disnake/ext/commands/help.py +++ b/disnake/ext/commands/help.py @@ -714,7 +714,7 @@ async def send_bot_help( The key of the mapping is the :class:`~.commands.Cog` that the command belongs to, or :data:`None` if there isn't one, and the value is a list of commands that belongs to that cog. """ - return None + return async def send_cog_help(self, cog: Cog) -> None: """|coro| @@ -742,7 +742,7 @@ async def send_cog_help(self, cog: Cog) -> None: cog: :class:`Cog` The cog that was requested for help. """ - return None + return async def send_group_help(self, group: Group[Any, ..., Any]) -> None: """|coro| @@ -770,7 +770,7 @@ async def send_group_help(self, group: Group[Any, ..., Any]) -> None: group: :class:`Group` The group that was requested for help. """ - return None + return async def send_command_help(self, command: Command[Any, ..., Any]) -> None: """|coro| @@ -808,7 +808,7 @@ async def send_command_help(self, command: Command[Any, ..., Any]) -> None: command: :class:`Command` The command that was requested for help. """ - return None + return async def prepare_help_command(self, ctx: Context[BotT], command: Optional[str] = None) -> None: """|coro| diff --git a/disnake/ext/commands/interaction_bot_base.py b/disnake/ext/commands/interaction_bot_base.py index 6d9f57cbbf..2eff783d7e 100644 --- a/disnake/ext/commands/interaction_bot_base.py +++ b/disnake/ext/commands/interaction_bot_base.py @@ -462,6 +462,7 @@ def get_slash_command( group = slash.children.get(chain[1]) if isinstance(group, SubCommandGroup): return group.children.get(chain[2]) + return None def get_user_command(self, name: str) -> Optional[InvokableUserCommand]: """Gets an :class:`InvokableUserCommand` from the internal list diff --git a/disnake/ext/commands/view.py b/disnake/ext/commands/view.py index f6e75c28d8..ebf0229adc 100644 --- a/disnake/ext/commands/view.py +++ b/disnake/ext/commands/view.py @@ -167,6 +167,7 @@ def get_quoted_word(self) -> Optional[str]: return "".join(result) result.append(current) + return None def __repr__(self) -> str: return ( diff --git a/disnake/ext/tasks/__init__.py b/disnake/ext/tasks/__init__.py index 085a889c6e..23423f1509 100644 --- a/disnake/ext/tasks/__init__.py +++ b/disnake/ext/tasks/__init__.py @@ -232,6 +232,7 @@ def seconds(self) -> Optional[float]: """ if self._seconds is not MISSING: return self._seconds + return None @property def minutes(self) -> Optional[float]: @@ -242,6 +243,7 @@ def minutes(self) -> Optional[float]: """ if self._minutes is not MISSING: return self._minutes + return None @property def hours(self) -> Optional[float]: @@ -252,6 +254,7 @@ def hours(self) -> Optional[float]: """ if self._hours is not MISSING: return self._hours + return None @property def time(self) -> Optional[List[datetime.time]]: @@ -262,6 +265,7 @@ def time(self) -> Optional[List[datetime.time]]: """ if self._time is not MISSING: return self._time.copy() + return None @property def current_loop(self) -> int: @@ -630,8 +634,7 @@ def _get_time_parameter( raise TypeError(msg) ret.append(t if t.tzinfo is not None else t.replace(tzinfo=utc)) - ret = sorted(set(ret)) # de-dupe and sort times - return ret + return sorted(set(ret)) # de-dupe and sort times def change_interval( self, diff --git a/disnake/guild.py b/disnake/guild.py index cabf40fe75..ac259a84ed 100644 --- a/disnake/guild.py +++ b/disnake/guild.py @@ -900,7 +900,7 @@ def key(t: ByCategoryItem) -> Tuple[Tuple[int, int], List[GuildChannel]]: def _resolve_channel(self, id: Optional[int], /) -> Optional[Union[GuildChannel, Thread]]: if id is None: - return + return None return self._channels.get(id) or self._threads.get(id) @@ -2549,12 +2549,11 @@ def convert(d: GuildChannelPayload) -> GuildChannel: if factory is None: raise InvalidData("Unknown channel type {type} for channel ID {id}.".format_map(d)) - channel = factory( + return factory( guild=self, state=self._state, data=d, # type: ignore ) - return channel return [convert(d) for d in data] @@ -4039,10 +4038,9 @@ async def create_role( fields["unicode_emoji"] = emoji data = await self._state.http.create_role(self.id, reason=reason, **fields) - role = Role(guild=self, data=data, state=self._state) # TODO: add to cache - return role + return Role(guild=self, data=data, state=self._state) async def edit_role_positions( self, positions: Dict[Snowflake, int], *, reason: Optional[str] = None @@ -4668,6 +4666,7 @@ async def chunk(self, *, cache: bool = True) -> Optional[List[Member]]: if not self._state.is_guild_evicted(self): return await self._state.chunk_guild(self, cache=cache) + return None async def query_members( self, diff --git a/disnake/interactions/base.py b/disnake/interactions/base.py index ddd6b779e9..7f5b055de0 100644 --- a/disnake/interactions/base.py +++ b/disnake/interactions/base.py @@ -1981,7 +1981,8 @@ async def delete(self, *, delay: Optional[float] = None) -> None: Deleting the message failed. """ if self._state._interaction.is_expired(): - return await super().delete(delay=delay) + await super().delete(delay=delay) + return if delay is not None: async def inner_call(delay: float = delay) -> None: diff --git a/disnake/member.py b/disnake/member.py index aae354f268..0c9cd63d1c 100644 --- a/disnake/member.py +++ b/disnake/member.py @@ -427,8 +427,7 @@ def _copy(cls, member: Member) -> Self: return self async def _get_channel(self) -> DMChannel: - ch = await self.create_dm() - return ch + return await self.create_dm() def _update(self, data: GuildMemberUpdateEvent) -> None: # the nickname change is optional, @@ -499,6 +498,7 @@ def _update_inner_user(self, user: UserPayload) -> Optional[Tuple[User, User]]: ) = modified # Signal to dispatch on_user_update return to_return, u + return None @property def status(self) -> Status: @@ -664,6 +664,7 @@ def activity(self) -> Optional[ActivityTypes]: """ if self.activities: return self.activities[0] + return None def mentioned_in(self, message: Message) -> bool: """Whether the member is mentioned in the specified message. diff --git a/disnake/message.py b/disnake/message.py index 62e5072e22..a224a5544c 100644 --- a/disnake/message.py +++ b/disnake/message.py @@ -470,8 +470,7 @@ async def read(self, *, use_cached: bool = False) -> bytes: The contents of the attachment. """ url = self.proxy_url if use_cached else self.url - data = await self._http.get_from_cdn(url) - return data + return await self._http.get_from_cdn(url) async def to_file( self, @@ -1376,7 +1375,7 @@ def _clear_emoji(self, emoji) -> Optional[Reaction]: break else: # didn't find anything so just return - return + return None del self.reactions[index] return reaction @@ -1779,7 +1778,7 @@ def system_content(self) -> Optional[str]: if self.type is MessageType.role_subscription_purchase: if not (data := self.role_subscription_data): - return + return None guild_name = f"**{self.guild.name}**" if self.guild else None if data.total_months_subscribed > 0: @@ -1833,12 +1832,12 @@ def system_content(self) -> Optional[str]: if self.type is MessageType.poll_result: if not self.embeds: - return + return None poll_result_embed = self.embeds[0] poll_embed_fields: Dict[str, str] = {} if not poll_result_embed._fields: - return + return None for field in poll_result_embed._fields: poll_embed_fields[field["name"]] = field["value"] diff --git a/disnake/poll.py b/disnake/poll.py index bea0109987..26a4c92e49 100644 --- a/disnake/poll.py +++ b/disnake/poll.py @@ -290,7 +290,7 @@ def created_at(self) -> Optional[datetime]: :data:`None` if this poll does not originate from the discord API. """ if not self.message: - return + return None return utils.snowflake_time(self.message.id) @property @@ -302,12 +302,12 @@ def expires_at(self) -> Optional[datetime]: """ # non-expiring poll if not self.duration: - return + return None created_at = self.created_at # manually built object if not created_at: - return + return None return created_at + self.duration @property @@ -321,7 +321,7 @@ def remaining_duration(self) -> Optional[timedelta]: if self.is_finalized: return timedelta(hours=0) if not self.expires_at or not self.message: - return + return None return self.expires_at - utils.utcnow() diff --git a/disnake/shard.py b/disnake/shard.py index c85ad2312f..7233601d64 100644 --- a/disnake/shard.py +++ b/disnake/shard.py @@ -461,7 +461,8 @@ async def launch_shard(self, gateway: str, shard_id: int, *, initial: bool = Fal except Exception: _log.exception("Failed to connect for shard_id: %s. Retrying...", shard_id) await asyncio.sleep(5.0) - return await self.launch_shard(gateway, shard_id) + await self.launch_shard(gateway, shard_id) + return # keep reading the shard while others connect self.__shards[shard_id] = ret = Shard(ws, self, self.__queue.put_nowait) diff --git a/disnake/state.py b/disnake/state.py index 9922963a40..652ef890ef 100644 --- a/disnake/state.py +++ b/disnake/state.py @@ -498,6 +498,7 @@ def _get_guild_application_command( granula = self._guild_application_commands.get(guild_id) if granula is not None: return granula.get(application_command_id) + return None def _add_guild_application_command( self, guild_id: int, application_command: APIApplicationCommand @@ -529,6 +530,7 @@ def _get_global_command_named( for cmd in self._global_application_commands.values(): if cmd.name == name and (cmd_type is None or cmd.type is cmd_type): return cmd + return None def _get_guild_command_named( self, guild_id: int, name: str, cmd_type: Optional[ApplicationCommandType] = None @@ -537,6 +539,7 @@ def _get_guild_command_named( for cmd in granula.values(): if cmd.name == name and (cmd_type is None or cmd.type is cmd_type): return cmd + return None @property def emojis(self) -> List[Emoji]: @@ -2261,6 +2264,7 @@ def get_channel(self, id: Optional[int]) -> Optional[Union[Channel, Thread]]: channel = guild._resolve_channel(id) if channel is not None: return channel + return None def create_message( self, diff --git a/disnake/ui/view.py b/disnake/ui/view.py index d97f526308..3dae4fb55f 100644 --- a/disnake/ui/view.py +++ b/disnake/ui/view.py @@ -159,12 +159,14 @@ async def __timeout_task_impl(self) -> None: return if self.__timeout_expiry is None: - return self._dispatch_timeout() + self._dispatch_timeout() + return # Check if we've elapsed our currently set timeout now = time.monotonic() if now >= self.__timeout_expiry: - return self._dispatch_timeout() + self._dispatch_timeout() + return # Wait N seconds to see if timeout data has been refreshed await asyncio.sleep(self.__timeout_expiry - now) @@ -223,7 +225,7 @@ def from_message(cls, message: Message, /, *, timeout: Optional[float] = 180.0) for component in walk_components(message.components): if isinstance(component, ActionRowComponent): continue - elif not isinstance(component, VALID_ACTION_ROW_MESSAGE_COMPONENT_TYPES): + if not isinstance(component, VALID_ACTION_ROW_MESSAGE_COMPONENT_TYPES): # can happen if message uses components v2 msg = f"Cannot construct view from message - unexpected {type(component).__name__}" raise TypeError(msg) @@ -360,7 +362,7 @@ async def _scheduled_task(self, item: Item, interaction: MessageInteraction) -> allow = await self.interaction_check(interaction) if not allow: - return + return None await item.callback(interaction) except Exception as e: diff --git a/disnake/user.py b/disnake/user.py index 807c6e5803..69343b3111 100644 --- a/disnake/user.py +++ b/disnake/user.py @@ -626,8 +626,7 @@ def __repr__(self) -> str: ) async def _get_channel(self) -> DMChannel: - ch = await self.create_dm() - return ch + return await self.create_dm() @property def dm_channel(self) -> Optional[DMChannel]: diff --git a/disnake/voice_client.py b/disnake/voice_client.py index 2a63c457a2..a1b7c93d9b 100644 --- a/disnake/voice_client.py +++ b/disnake/voice_client.py @@ -369,8 +369,7 @@ async def connect(self, *, reconnect: bool, timeout: float) -> None: await asyncio.sleep(1 + i * 2.0) await self.voice_disconnect() continue - else: - raise + raise if self._runner is MISSING: self._runner = self.loop.create_task(self.poll_voice_ws(reconnect)) @@ -447,8 +446,7 @@ async def poll_voice_ws(self, reconnect: bool) -> None: ) await self.disconnect() break - else: - continue + continue if not reconnect: await self.disconnect() diff --git a/disnake/webhook/sync.py b/disnake/webhook/sync.py index d5753f0aa9..130baac445 100644 --- a/disnake/webhook/sync.py +++ b/disnake/webhook/sync.py @@ -1152,6 +1152,7 @@ def send( f.close() if wait: return self._create_message(data, thread=thread, thread_name=thread_name) + return None def fetch_message( self, id: int, /, *, thread: Optional[Snowflake] = None diff --git a/docs/extensions/fulltoc.py b/docs/extensions/fulltoc.py index 62499afd4a..96157c2702 100644 --- a/docs/extensions/fulltoc.py +++ b/docs/extensions/fulltoc.py @@ -96,8 +96,7 @@ def get_rendered_toctree(builder: StandaloneHTMLBuilder, docname: str, index: st index, **kwargs, ) - rendered_toc = builder.render_partial(fulltoc)["fragment"] - return rendered_toc + return builder.render_partial(fulltoc)["fragment"] def build_full_toctree( diff --git a/examples/basic_voice.py b/examples/basic_voice.py index 0ff34a7b5f..2191c27ffe 100644 --- a/examples/basic_voice.py +++ b/examples/basic_voice.py @@ -68,7 +68,8 @@ def __init__(self, bot: commands.Bot): async def join(self, ctx, *, channel: disnake.VoiceChannel): """Joins a voice channel""" if ctx.voice_client is not None: - return await ctx.voice_client.move_to(channel) + await ctx.voice_client.move_to(channel) + return await channel.connect() @@ -105,7 +106,8 @@ async def _play_url(self, ctx, *, url: str, stream: bool): async def volume(self, ctx, volume: int): """Changes the player's volume""" if ctx.voice_client is None: - return await ctx.send("Not connected to a voice channel.") + await ctx.send("Not connected to a voice channel.") + return ctx.voice_client.source.volume = volume / 100 await ctx.send(f"Changed volume to {volume}%") diff --git a/examples/converters.py b/examples/converters.py index 34ea814127..736fd3478b 100644 --- a/examples/converters.py +++ b/examples/converters.py @@ -39,7 +39,8 @@ async def userinfo_error(ctx: commands.Context, error: commands.CommandError): # If the conversion above fails for any reason, it will raise `commands.UserNotFound` # so we handle this in this error handler: if isinstance(error, commands.UserNotFound): - return await ctx.send("Couldn't find that user.") + await ctx.send("Couldn't find that user.") + return @bot.command() @@ -68,7 +69,8 @@ async def multiply(ctx: commands.Context, number: int, maybe: bool): # See: https://docs.disnake.dev/en/stable/ext/commands/commands.html#bool if maybe is True: - return await ctx.send(str(number * 2)) + await ctx.send(str(number * 2)) + return await ctx.send(str(number * 5)) diff --git a/examples/guessing_game.py b/examples/guessing_game.py index cac14386b7..d5cd399fca 100644 --- a/examples/guessing_game.py +++ b/examples/guessing_game.py @@ -27,7 +27,8 @@ def is_guess_message(m: disnake.Message): try: guess = await ctx.bot.wait_for("message", check=is_guess_message, timeout=10) except asyncio.TimeoutError: - return await ctx.send(f"Sorry, you took too long. The answer was {answer}.") + await ctx.send(f"Sorry, you took too long. The answer was {answer}.") + return if int(guess.content) == answer: await ctx.send("You guessed correctly!") diff --git a/examples/views/tic_tac_toe.py b/examples/views/tic_tac_toe.py index 32c0c222fb..39d470f6f5 100644 --- a/examples/views/tic_tac_toe.py +++ b/examples/views/tic_tac_toe.py @@ -101,7 +101,7 @@ def check_board_winner(self): def check_winner(value: int) -> Optional[Player]: if value == Player.O * 3: return Player.O - elif value == Player.X * 3: + if value == Player.X * 3: return Player.X return None diff --git a/pyproject.toml b/pyproject.toml index 28e6b509e0..201d700083 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -161,7 +161,7 @@ ignore = [ ## flake8-pyi "PYI", # TODO: enable, in separate PR (most have autofixes) ## flake8-return - "RET", # TODO: enable, most have autofixes. + "RET505", "RET506", # not likely to be enabled ## flake8-self "SLF", # private member access, this is unlikely to be enabled. ## flake8-simplify diff --git a/scripts/codemods/overloads_no_missing.py b/scripts/codemods/overloads_no_missing.py index 6c56a9be07..d0477197a2 100644 --- a/scripts/codemods/overloads_no_missing.py +++ b/scripts/codemods/overloads_no_missing.py @@ -40,6 +40,4 @@ def leave_FunctionDef( new_params.append(param) kw[param_type] = new_params - node = node.with_deep_changes(node.params, **kw) - - return node + return node.with_deep_changes(node.params, **kw) diff --git a/scripts/codemods/typed_permissions.py b/scripts/codemods/typed_permissions.py index ec900515df..aa02840699 100644 --- a/scripts/codemods/typed_permissions.py +++ b/scripts/codemods/typed_permissions.py @@ -138,7 +138,7 @@ def leave_FunctionDef( msg = 'a function cannot be decorated with "_overload_with_permissions" and not take any kwargs unless it is an overload.' raise RuntimeError(msg) # always true if this isn't an overload - elif node.params.star_kwarg: + if node.params.star_kwarg: # use the existing annotation if one exists annotation = node.params.star_kwarg.annotation if annotation is None: @@ -166,8 +166,7 @@ def leave_FunctionDef( params = params.with_changes(kwonly_params=kwonly_params) if is_overload: - node = node.with_changes(params=params) - return node + return node.with_changes(params=params) # make an overload before permissions empty_overload = node.deep_clone().with_changes(params=empty_overload_params) diff --git a/scripts/new_typehints.py b/scripts/new_typehints.py index 5c0c44afdc..1acb49646c 100644 --- a/scripts/new_typehints.py +++ b/scripts/new_typehints.py @@ -181,9 +181,7 @@ def replace_all_unions(text: str) -> str: part = ANY.sub(r"\1:data:`~typing.Any`", part) s += part - s = NONE.sub(r":data:`None`", s) - - return s + return NONE.sub(r":data:`None`", s) def process_file(file_path) -> None: diff --git a/tests/helpers.py b/tests/helpers.py index bcf957d98e..a879dbda2e 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -69,11 +69,9 @@ async def wrap_async(*args, **kwargs): return wrap_async # type: ignore - else: + @functools.wraps(func) + def wrap_sync(*args, **kwargs): + with self: + return func(*args, **kwargs) - @functools.wraps(func) - def wrap_sync(*args, **kwargs): - with self: - return func(*args, **kwargs) - - return wrap_sync # type: ignore + return wrap_sync # type: ignore