Skip to content

Commit 8429ded

Browse files
committed
Address PR comments and fix flake8 errors
1 parent e1b0cf4 commit 8429ded

11 files changed

+58
-79
lines changed

hikari/api/event_factory.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,9 +1422,9 @@ def deserialize_stage_instance_create_event(
14221422
14231423
Parameters
14241424
----------
1425-
shard : hikari.api.shard.GatewayShard
1425+
shard
14261426
The shard that emitted this event.
1427-
payload : hikari.internal.data_binding.JSONObject
1427+
payload
14281428
The dict payload to parse.
14291429
14301430
Returns
@@ -1434,21 +1434,21 @@ def deserialize_stage_instance_create_event(
14341434
"""
14351435

14361436
@abc.abstractmethod
1437-
def deserialize_stage_instance_edit_event(
1437+
def deserialize_stage_instance_update_event(
14381438
self, shard: gateway_shard.GatewayShard, payload: data_binding.JSONObject
1439-
) -> stage_events.StageInstanceEditEvent:
1439+
) -> stage_events.StageInstanceUpdateEvent:
14401440
"""Parse a raw payload from Discord into a stage instance update event object.
14411441
14421442
Parameters
14431443
----------
1444-
shard : hikari.api.shard.GatewayShard
1444+
shard
14451445
The shard that emitted this event.
1446-
payload : hikari.internal.data_binding.JSONObject
1446+
payload
14471447
The dict payload to parse.
14481448
14491449
Returns
14501450
-------
1451-
hikari.events.voice_events.StageInstanceEditEvent
1451+
hikari.events.voice_events.StageInstanceUpdateEvent
14521452
The parsed stage instance update event object.
14531453
"""
14541454

@@ -1460,9 +1460,9 @@ def deserialize_stage_instance_delete_event(
14601460
14611461
Parameters
14621462
----------
1463-
shard : hikari.api.shard.GatewayShard
1463+
shard
14641464
The shard that emitted this event.
1465-
payload : hikari.internal.data_binding.JSONObject
1465+
payload
14661466
The dict payload to parse.
14671467
14681468
Returns

hikari/events/stage_events.py

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# cython: language_level=3
33
# Copyright (c) 2020 Nekokatt
4-
# Copyright (c) 2021 davfsa
4+
# Copyright (c) 2021-present davfsa
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
77
# of this software and associated documentation files (the "Software"), to deal
@@ -48,15 +48,9 @@ class StageInstanceEvent(shard_events.ShardEvent, abc.ABC):
4848
__slots__: typing.Sequence[str] = ()
4949

5050
@property
51-
@abc.abstractmethod
52-
def stage_instance_id(self) -> snowflakes.Snowflake:
53-
"""ID of the stage instance that this event relates to.
54-
55-
Returns
56-
-------
57-
hikari.snowflakes.Snowflake
58-
The ID of the stage instance that this event relates to.
59-
"""
51+
def app(self) -> traits.RESTAware:
52+
# <<inherited docstring from Event>>.
53+
return self.stage_instance.app
6054

6155
@property
6256
@abc.abstractmethod
@@ -69,6 +63,17 @@ def stage_instance(self) -> StageInstance:
6963
The stage instance that this event relates to.
7064
"""
7165

66+
@property
67+
def stage_instance_id(self) -> snowflakes.Snowflake:
68+
"""ID of the stage instance that this event relates to.
69+
70+
Returns
71+
-------
72+
hikari.snowflakes.Snowflake
73+
The ID of the stage instance that this event relates to.
74+
"""
75+
return self.stage_instance.id
76+
7277

7378
@attrs_extensions.with_copy
7479
@attr.define(kw_only=True, weakref_slot=False)
@@ -82,37 +87,18 @@ class StageInstanceCreateEvent(StageInstanceEvent):
8287
stage_instance: StageInstance = attr.field()
8388
"""The stage instance that was created."""
8489

85-
@property
86-
def app(self) -> traits.RESTAware:
87-
# <<inherited docstring from Event>>.
88-
return self.stage_instance.app
89-
90-
@property
91-
def stage_instance_id(self) -> snowflakes.Snowflake:
92-
# <<inherited docstring from StageInstanceEvent>>.
93-
return self.stage_instance.id
94-
9590

9691
@attrs_extensions.with_copy
9792
@attr.define(kw_only=True, weakref_slot=False)
9893
@base_events.requires_intents(intents.Intents.GUILDS)
99-
class StageInstanceEditEvent(StageInstanceEvent):
100-
"""Event fired when a stage instance is edited."""
94+
class StageInstanceUpdateEvent(StageInstanceEvent):
95+
"""Event fired when a stage instance is updated."""
10196

10297
shard: gateway_shard.GatewayShard = attr.field(metadata={attrs_extensions.SKIP_DEEP_COPY: True})
10398
# <<inherited docstring from ShardEvent>>.
10499

105100
stage_instance: StageInstance = attr.field()
106-
"""The stage instance that was edited."""
107-
108-
@property
109-
def app(self) -> traits.RESTAware:
110-
# <<inherited docstring from Event>>.
111-
return self.stage_instance.app
112-
113-
@property
114-
def stage_instance_id(self) -> snowflakes.Snowflake:
115-
return self.stage_instance.id
101+
"""The stage instance that was updated."""
116102

117103

118104
@attrs_extensions.with_copy
@@ -126,12 +112,3 @@ class StageInstanceDeleteEvent(StageInstanceEvent):
126112

127113
stage_instance: StageInstance = attr.field()
128114
"""The stage instance that was deleted."""
129-
130-
@property
131-
def app(self) -> traits.RESTAware:
132-
# <<inherited docstring from Event>>.
133-
return self.stage_instance.app
134-
135-
@property
136-
def stage_instance_id(self) -> snowflakes.Snowflake:
137-
return self.stage_instance.id

hikari/impl/entity_factory.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,9 +1472,8 @@ def deserialize_guild_private_thread(
14721472
)
14731473

14741474
def deserialize_stage_instance(self, payload: data_binding.JSONObject) -> stage_instances.StageInstance:
1475-
guild_scheduled_event_id = (
1476-
snowflakes.Snowflake(payload["guild_scheduled_event_id"]) if payload["guild_scheduled_event_id"] else None
1477-
)
1475+
raw_event_id = payload["guild_scheduled_event_id"]
1476+
guild_scheduled_event_id = snowflakes.Snowflake(raw_event_id) if raw_event_id else None
14781477

14791478
return stage_instances.StageInstance(
14801479
app=self._app,

hikari/impl/event_factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,10 +967,10 @@ def deserialize_stage_instance_create_event(
967967
shard=shard, stage_instance=self._app.entity_factory.deserialize_stage_instance(payload)
968968
)
969969

970-
def deserialize_stage_instance_edit_event(
970+
def deserialize_stage_instance_update_event(
971971
self, shard: gateway_shard.GatewayShard, payload: data_binding.JSONObject
972-
) -> stage_events.StageInstanceEditEvent:
973-
return stage_events.StageInstanceEditEvent(
972+
) -> stage_events.StageInstanceUpdateEvent:
973+
return stage_events.StageInstanceUpdateEvent(
974974
shard=shard, stage_instance=self._app.entity_factory.deserialize_stage_instance(payload)
975975
)
976976

hikari/impl/event_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from hikari.events import role_events
4949
from hikari.events import scheduled_events
5050
from hikari.events import shard_events
51+
from hikari.events import stage_events
5152
from hikari.events import typing_events
5253
from hikari.events import user_events
5354
from hikari.events import voice_events
@@ -889,18 +890,20 @@ async def on_entitlement_update(self, shard: gateway_shard.GatewayShard, payload
889890
"""See https://discord.com/developers/docs/topics/gateway-events#entitlement-update for more info."""
890891
await self.dispatch(self._event_factory.deserialize_entitlement_update_event(shard, payload))
891892

893+
@event_manager_base.filtered(stage_events.StageInstanceCreateEvent)
892894
async def on_stage_instance_create(
893895
self, shard: gateway_shard.GatewayShard, payload: data_binding.JSONObject
894896
) -> None:
895897
await self.dispatch(self._event_factory.deserialize_stage_instance_create_event(shard, payload))
896898

899+
@event_manager_base.filtered(stage_events.StageInstanceUpdateEvent)
897900
async def on_stage_instance_update(
898901
self, shard: gateway_shard.GatewayShard, payload: data_binding.JSONObject
899902
) -> None:
900-
await self.dispatch(self._event_factory.deserialize_stage_instance_edit_event(shard, payload))
903+
await self.dispatch(self._event_factory.deserialize_stage_instance_update_event(shard, payload))
901904

905+
@event_manager_base.filtered(stage_events.StageInstanceDeleteEvent)
902906
async def on_stage_instance_delete(
903907
self, shard: gateway_shard.GatewayShard, payload: data_binding.JSONObject
904908
) -> None:
905909
await self.dispatch(self._event_factory.deserialize_stage_instance_delete_event(shard, payload))
906-
# TODO

hikari/stage_instances.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
# cython: language_level=3
33
# Copyright (c) 2020 Nekokatt
4-
# Copyright (c) 2021 davfsa
4+
# Copyright (c) 2021-present davfsa
55
#
66
# Permission is hereby granted, free of charge, to any person obtaining a copy
77
# of this software and associated documentation files (the "Software"), to deal
@@ -75,7 +75,7 @@ def get_channel(self) -> typing.Optional[channels.GuildStageChannel]:
7575
7676
Returns
7777
-------
78-
hikari.channels.GuildStageChannel
78+
typing.Optional[hikari.channels.GuildStageChannel]
7979
The guild stage channel where this stage instance was created.
8080
"""
8181
if not isinstance(self.app, traits.CacheAware):

tests/hikari/events/test_stage_events.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
class TestStageInstanceCreateEvent:
31-
@pytest.fixture()
31+
@pytest.fixture
3232
def event(self):
3333
return stage_events.StageInstanceCreateEvent(shard=object(), stage_instance=mock.Mock())
3434

@@ -40,10 +40,10 @@ def test_stage_instance_id_property(self, event):
4040
assert event.stage_instance_id == 1234
4141

4242

43-
class TestStageInstanceEditEvent:
44-
@pytest.fixture()
43+
class TestStageInstanceUpdateEvent:
44+
@pytest.fixture
4545
def event(self):
46-
return stage_events.StageInstanceEditEvent(
46+
return stage_events.StageInstanceUpdateEvent(
4747
shard=object(), stage_instance=mock.Mock(stage_instances.StageInstance)
4848
)
4949

@@ -56,7 +56,7 @@ def test_stage_instance_id_property(self, event):
5656

5757

5858
class TestStageInstanceDeleteEvent:
59-
@pytest.fixture()
59+
@pytest.fixture
6060
def event(self):
6161
return stage_events.StageInstanceDeleteEvent(
6262
shard=object(), stage_instance=mock.Mock(stage_instances.StageInstance)

tests/hikari/impl/test_entity_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7215,7 +7215,7 @@ def test_deserialize_sku(self, entity_factory_impl, sku_payload):
72157215
# Stage instance models #
72167216
#########################
72177217

7218-
@pytest.fixture()
7218+
@pytest.fixture
72197219
def stage_instance_payload(self):
72207220
return {
72217221
"id": "840647391636226060",

tests/hikari/impl/test_event_factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ def test_deserialize_stage_instance_create_event(self, event_factory, mock_app,
15401540
assert event.stage_instance_id == mock_app.entity_factory.deserialize_stage_instance.return_value.id
15411541
assert event.stage_instance == mock_app.entity_factory.deserialize_stage_instance.return_value
15421542

1543-
def test_deserialize_stage_instance_edit_event(self, event_factory, mock_app, mock_shard):
1543+
def test_deserialize_stage_instance_update_event(self, event_factory, mock_app, mock_shard):
15441544
mock_payload = {
15451545
"id": "840647391636226060",
15461546
"guild_id": "197038439483310086",
@@ -1549,8 +1549,8 @@ def test_deserialize_stage_instance_edit_event(self, event_factory, mock_app, mo
15491549
"privacy_level": 2,
15501550
"discoverable_disabled": True,
15511551
}
1552-
event = event_factory.deserialize_stage_instance_edit_event(mock_shard, mock_payload)
1553-
assert isinstance(event, stage_events.StageInstanceEditEvent)
1552+
event = event_factory.deserialize_stage_instance_update_event(mock_shard, mock_payload)
1553+
assert isinstance(event, stage_events.StageInstanceUpdateEvent)
15541554

15551555
assert event.shard is mock_shard
15561556
assert event.app is event.stage_instance.app

tests/hikari/impl/test_event_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ async def test_on_guild_audit_log_entry_create(
16931693
event_factory.deserialize_audit_log_entry_create_event.return_value
16941694
)
16951695

1696-
@pytest.mark.asyncio()
1696+
@pytest.mark.asyncio
16971697
async def test_on_stage_instance_create(
16981698
self,
16991699
event_manager_impl: event_manager.EventManagerImpl,
@@ -1716,7 +1716,7 @@ async def test_on_stage_instance_create(
17161716
event_factory.deserialize_stage_instance_create_event.return_value
17171717
)
17181718

1719-
@pytest.mark.asyncio()
1719+
@pytest.mark.asyncio
17201720
async def test_on_stage_instance_update(
17211721
self,
17221722
event_manager_impl: event_manager.EventManagerImpl,
@@ -1734,12 +1734,12 @@ async def test_on_stage_instance_update(
17341734

17351735
await event_manager_impl.on_stage_instance_update(shard, payload)
17361736

1737-
event_factory.deserialize_stage_instance_edit_event.assert_called_once_with(shard, payload)
1737+
event_factory.deserialize_stage_instance_update_event.assert_called_once_with(shard, payload)
17381738
event_manager_impl.dispatch.assert_awaited_once_with(
1739-
event_factory.deserialize_stage_instance_edit_event.return_value
1739+
event_factory.deserialize_stage_instance_update_event.return_value
17401740
)
17411741

1742-
@pytest.mark.asyncio()
1742+
@pytest.mark.asyncio
17431743
async def test_on_stage_instance_delete(
17441744
self,
17451745
event_manager_impl: event_manager.EventManagerImpl,

tests/hikari/test_stage_instances.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
from hikari import stage_instances
2929

3030

31-
@pytest.fixture()
31+
@pytest.fixture
3232
def mock_app():
3333
return mock.Mock()
3434

3535

3636
class TestStageInstance:
37-
@pytest.fixture()
37+
@pytest.fixture
3838
def stage_instance(self, mock_app):
3939
return stage_instances.StageInstance(
4040
app=mock_app,
@@ -79,7 +79,7 @@ def test_get_channel_when_no_cache_trait(self, stage_instance):
7979

8080
assert stage_instance.get_channel() is None
8181

82-
@pytest.mark.asyncio()
82+
@pytest.mark.asyncio
8383
async def test_fetch_channel(self, stage_instance):
8484
mock_stage_channel = mock.Mock(channels.GuildStageChannel)
8585
stage_instance.app.rest.fetch_channel = mock.AsyncMock(return_value=mock_stage_channel)
@@ -99,14 +99,14 @@ def test_get_guild_when_no_cache_trait(self, stage_instance):
9999

100100
assert stage_instance.get_guild() is None
101101

102-
@pytest.mark.asyncio()
102+
@pytest.mark.asyncio
103103
async def test_fetch_guild(self, stage_instance):
104104
stage_instance.app.rest.fetch_guild = mock.AsyncMock()
105105

106106
assert await stage_instance.fetch_guild() == stage_instance.app.rest.fetch_guild.return_value
107107
stage_instance.app.rest.fetch_guild.assert_awaited_once_with(420)
108108

109-
@pytest.mark.asyncio()
109+
@pytest.mark.asyncio
110110
async def test_fetch_scheduled_event(self, stage_instance):
111111
stage_instance.app.rest.fetch_scheduled_event = mock.AsyncMock()
112112

0 commit comments

Comments
 (0)