Skip to content

Commit

Permalink
lint: resolve new ruff issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv committed Nov 22, 2024
1 parent e777f95 commit 0ddfb91
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def localize(self, store: LocalizationProtocol) -> None:
o.localize(store)


class ApplicationCommand(ABC):
class ApplicationCommand(ABC): # noqa: B024 # this will get refactored eventually
"""The base class for application commands.
The following classes implement this ABC:
Expand Down
2 changes: 1 addition & 1 deletion disnake/ext/commands/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ def get_converter(param: inspect.Parameter) -> Any:


def is_generic_type(tp: Any, *, _GenericAlias: Type = _GenericAlias) -> bool:
return isinstance(tp, type) and issubclass(tp, Generic) or isinstance(tp, _GenericAlias)
return (isinstance(tp, type) and issubclass(tp, Generic)) or isinstance(tp, _GenericAlias)


CONVERTER_MAPPING: Dict[Type[Any], Type[Converter]] = {
Expand Down
2 changes: 1 addition & 1 deletion disnake/ext/commands/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ def parse_parameter(self, param: inspect.Parameter) -> None:
self.param_name = param.name

def parse_doc(self, doc: disnake.utils._DocstringParam) -> None:
if self.type == str and doc["type"] is not None:
if self.type is str and doc["type"] is not None:
self.parse_annotation(doc["type"])

self.description = self.description or doc["description"]
Expand Down
2 changes: 1 addition & 1 deletion disnake/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def next_iteration(self) -> Optional[datetime.datetime]:
"""
if self._task is MISSING:
return None
elif self._task and self._task.done() or self._stop_next_iteration:
elif (self._task and self._task.done()) or self._stop_next_iteration:
return None
return self._next_iteration

Expand Down
23 changes: 9 additions & 14 deletions disnake/interactions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,10 @@ def __init__(self, *, data: InteractionPayload, state: ConnectionState) -> None:
self.author = (
isinstance(guild_fallback, Guild)
and guild_fallback.get_member(int(member["user"]["id"]))
or Member(
state=self._state,
guild=guild_fallback, # type: ignore # may be `Object`
data=member,
)
) or Member(
state=self._state,
guild=guild_fallback, # type: ignore # may be `Object`
data=member,
)
self._permissions = int(member.get("permissions", 0))
elif user := data.get("user"):
Expand Down Expand Up @@ -1915,15 +1914,11 @@ def __init__(
user_id = int(str_id)
member = members.get(str_id)
if member is not None:
self.members[user_id] = (
guild
and guild.get_member(user_id)
or Member(
data=member,
user_data=user,
guild=guild_fallback, # type: ignore
state=state,
)
self.members[user_id] = (guild and guild.get_member(user_id)) or Member(
data=member,
user_data=user,
guild=guild_fallback, # type: ignore
state=state,
)
else:
self.users[user_id] = User(state=state, data=user)
Expand Down
16 changes: 6 additions & 10 deletions disnake/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def _add_global_application_command(
/,
) -> None:
if not application_command.id:
AssertionError("The provided application command does not have an ID")
raise AssertionError("The provided application command does not have an ID")
self._global_application_commands[application_command.id] = application_command

def _remove_global_application_command(self, application_command_id: int, /) -> None:
Expand All @@ -478,7 +478,7 @@ def _add_guild_application_command(
self, guild_id: int, application_command: APIApplicationCommand
) -> None:
if not application_command.id:
AssertionError("The provided application command does not have an ID")
raise AssertionError("The provided application command does not have an ID")
try:
granula = self._guild_application_commands[guild_id]
granula[application_command.id] = application_command
Expand Down Expand Up @@ -2100,14 +2100,10 @@ def _get_partial_interaction_channel(

# the factory can't be a DMChannel or GroupChannel here
data.setdefault("position", 0) # type: ignore
return (
isinstance(guild, Guild)
and guild.get_channel_or_thread(channel_id)
or factory(
guild=guild, # type: ignore # FIXME: create proper fallback guild instead of passing Object
state=self,
data=data, # type: ignore # generic payload type
)
return (isinstance(guild, Guild) and guild.get_channel_or_thread(channel_id)) or factory(
guild=guild, # type: ignore # FIXME: create proper fallback guild instead of passing Object
state=self,
data=data, # type: ignore # generic payload type
)

def get_channel(self, id: Optional[int]) -> Optional[Union[Channel, Thread]]:
Expand Down
2 changes: 1 addition & 1 deletion disnake/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ def evaluate_annotation(
return cache[tp]

# this is how annotations are supposed to be unstringifed
evaluated = eval(tp, globals, locals) # noqa: PGH001, S307
evaluated = eval(tp, globals, locals) # noqa: S307
# recurse to resolve nested args further
evaluated = evaluate_annotation(evaluated, globals, locals, cache)

Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ ignore = [
"RUF005", # might not be actually faster
"RUF006", # might not be an issue/very extreme cases

# we keep __all__ and __slots__ (roughly) sorted by source, not alphabetically
"RUF022",
"RUF023",

# calling subprocess with dynamic arguments is generally fine, the only way to avoid this is ignoring it
"S603",

Expand Down Expand Up @@ -259,6 +263,13 @@ mark-parentheses = false
[tool.ruff.lint.flake8-tidy-imports.banned-api]
"subprocess".msg = "Consider possible security implications associated with the subprocess module." # replaces S404

[tool.ruff.lint.flake8-bugbear]
extend-immutable-calls = [
# this is immutable, except for storing locks, which are fine to share across contexts
"disnake.webhook.async_.AsyncWebhookAdapter",
]


[tool.towncrier]
template = "changelog/_template.rst.jinja"
package = "disnake"
Expand Down
6 changes: 3 additions & 3 deletions tests/ext/commands/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def test_nan(self, value) -> None:

def test_valid(self) -> None:
x: Any = commands.Range[int, -1, 2]
assert x.underlying_type == int
assert x.underlying_type is int

x: Any = commands.Range[float, ..., 23.45]
assert x.underlying_type == float
assert x.underlying_type is float


class TestString:
Expand Down Expand Up @@ -211,7 +211,7 @@ def test_optional(self, annotation_str) -> None:

assert info.min_value == 1
assert info.max_value == 2
assert info.type == int
assert info.type is int


class TestIsolateSelf:
Expand Down

0 comments on commit 0ddfb91

Please sign in to comment.