Skip to content

Commit

Permalink
some changes to pass the linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergeileduc committed Jan 13, 2023
1 parent 24ed260 commit 0961897
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
"editor.rulers": [
120
],
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
}
3 changes: 2 additions & 1 deletion discord/ext/test/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
JsonDict = typing.Dict[str, JsonVal]
JsonList = typing.List[JsonVal]
Callback = typing.Callable[..., typing.Coroutine[None, None, None]]
AnyChannel = typing.Union[discord.TextChannel, discord.CategoryChannel, discord.abc.GuildChannel, discord.abc.PrivateChannel]
AnyChannel = typing.Union[discord.TextChannel, discord.CategoryChannel,
discord.abc.GuildChannel, discord.abc.PrivateChannel]
10 changes: 5 additions & 5 deletions discord/ext/test/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _get_higher_locs(num: int) -> typing.Dict[str, typing.Any]:
class FakeRequest(typing.NamedTuple):
"""
A fake web response, for use with discord ``HTTPException``\ s
"""
""" # noqa: W605
status: int
reason: str

Expand Down Expand Up @@ -858,8 +858,8 @@ def make_message(
CHANNEL_MENTION: typing.Pattern = re.compile(r"<#[0-9]{17,21}>", re.MULTILINE)


def find_user_mentions(content: typing.Optional[str], guild: typing.Optional[discord.Guild]) -> typing.List[
discord.Member]:
def find_user_mentions(content: typing.Optional[str],
guild: typing.Optional[discord.Guild]) -> typing.List[discord.Member]:
if guild is None or content is None:
return [] # TODO: Check for dm user mentions
matches = re.findall(MEMBER_MENTION, content)
Expand All @@ -873,8 +873,8 @@ def find_role_mentions(content: typing.Optional[str], guild: typing.Optional[dis
return matches


def find_channel_mentions(content: typing.Optional[str], guild: typing.Optional[discord.Guild]) -> typing.List[
_types.AnyChannel]:
def find_channel_mentions(content: typing.Optional[str],
guild: typing.Optional[discord.Guild]) -> typing.List[_types.AnyChannel]:
if guild is None or content is None:
return []
matches = re.findall(CHANNEL_MENTION, content)
Expand Down
6 changes: 4 additions & 2 deletions discord/ext/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def make_user_dict(
) -> _types.JsonDict: ...


def make_user_dict(username: str, discrim: typing.Union[str, int], avatar: str, id_num: int = -1, flags: int = 0, **kwargs: typing.Any) -> _types.JsonDict:
def make_user_dict(username: str, discrim: typing.Union[str, int], avatar: str, id_num: int = -1, flags: int = 0,
**kwargs: typing.Any) -> _types.JsonDict:
if isinstance(discrim, int):
assert 0 < discrim < 10000
discrim = f"{discrim:04}"
Expand Down Expand Up @@ -260,7 +261,8 @@ def make_dm_channel_dict(user: discord.User, id_num: int = -1, **kwargs: typing.
return make_channel_dict(discord.ChannelType.private, id_num, recipients=[dict_from_user(user)], **kwargs)


def dict_from_overwrite(target: typing.Union[discord.Member, discord.Role], overwrite: discord.PermissionOverwrite) -> _types.JsonDict:
def dict_from_overwrite(target: typing.Union[discord.Member, discord.Role],
overwrite: discord.PermissionOverwrite) -> _types.JsonDict:
allow, deny = overwrite.pair()
ovr = {
'id': target.id,
Expand Down
6 changes: 4 additions & 2 deletions discord/ext/test/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ async def remove_role(member: discord.Member, role: discord.Role) -> None:


@require_config
async def add_reaction(user: typing.Union[discord.user.BaseUser, discord.abc.User], message: discord.Message, emoji: str) -> None:
async def add_reaction(user: typing.Union[discord.user.BaseUser, discord.abc.User],
message: discord.Message, emoji: str) -> None:
"""
Add a reaction to a message, as if added by another user
Expand All @@ -276,7 +277,8 @@ async def add_reaction(user: typing.Union[discord.user.BaseUser, discord.abc.Use


@require_config
async def remove_reaction(user: typing.Union[discord.user.BaseUser, discord.abc.User], message: discord.Message, emoji: str) -> None:
async def remove_reaction(user: typing.Union[discord.user.BaseUser, discord.abc.User],
message: discord.Message, emoji: str) -> None:
"""
Remove a reaction from a message, as if done by another user
Expand Down
6 changes: 4 additions & 2 deletions discord/ext/test/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class FakeState(dstate.ConnectionState):

http: 'back.FakeHttp' # String because of circular import

def __init__(self, client: discord.Client, http: dhttp.HTTPClient, user: discord.ClientUser = None, loop: asyncio.AbstractEventLoop = None) -> None:
def __init__(self, client: discord.Client, http: dhttp.HTTPClient, user: discord.ClientUser = None,
loop: asyncio.AbstractEventLoop = None) -> None:
if loop is None:
loop = asyncio.get_event_loop()
super().__init__(dispatch=client.dispatch,
Expand Down Expand Up @@ -59,7 +60,8 @@ def start_dispatch(self) -> None:
self._do_dispatch = True

# TODO: Respect limit parameters
async def query_members(self, guild: discord.Guild, query: str, limit: int, user_ids: int, cache: bool, presences: bool) -> None:
async def query_members(self, guild: discord.Guild, query: str, limit: int, user_ids: int,
cache: bool, presences: bool) -> None:
guild: discord.Guild = discord.utils.get(self.guilds, id=guild.id)
return guild.members

Expand Down
2 changes: 1 addition & 1 deletion tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ async def test_member_join(bot):
)
message_dict = dpytest.back.facts.make_message_dict(channel, author, attachments=[attach])
try:
message: discord.Message = discord.Message(state=dpytest.back.get_state(), channel=channel, data=message_dict)
message: discord.Message = discord.Message(state=dpytest.back.get_state(), channel=channel, data=message_dict) # noqa: E501,F841 (variable never used)
except Exception as err:
pytest.fail(str(err))
2 changes: 1 addition & 1 deletion tests/test_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def test_edit_role(bot):
await bot.guilds[0].create_role(name="TestRole") # Role object
assert len(bot.guilds[0].roles) == 3
staff_role = bot.guilds[0].roles[1]
await staff_role.edit(permissions=discord.Permissions(8), colour=discord.Color.red(), hoist=True, mentionable=True, position=2)
await staff_role.edit(permissions=discord.Permissions(8), colour=discord.Color.red(), hoist=True, mentionable=True, position=2) # noqa: E501
assert bot.guilds[0].roles[2] == staff_role
assert bot.guilds[0].roles[2].colour == discord.Color.red()
assert bot.guilds[0].roles[2].hoist is True
Expand Down

0 comments on commit 0961897

Please sign in to comment.