Skip to content

Commit

Permalink
Refactor & cleanup return types
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekuruu committed Oct 15, 2024
1 parent bb20d1a commit bd1cc0a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions osu/objects/beatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BeatmapInfo:
checksum: str

@classmethod
def decode(cls, stream: StreamIn):
def decode(cls, stream: StreamIn) -> "BeatmapInfo":
return BeatmapInfo(
stream.s16(),
stream.s32(),
Expand Down Expand Up @@ -53,7 +53,7 @@ class OnlineBeatmap:
difficulties: List[Tuple[str, Mode]]

@classmethod
def parse(cls, string: str):
def parse(cls, string: str) -> "OnlineBeatmap":
args = string.split("|")
return OnlineBeatmap(
args[0],
Expand Down
8 changes: 4 additions & 4 deletions osu/objects/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __hash__(self) -> int:
def __eq__(self, other: object) -> bool:
return self.name == other.name

def join(self):
def join(self) -> None:
"""Join this channel"""
if self.joined:
return
Expand All @@ -39,7 +39,7 @@ def join(self):

self.game.bancho.enqueue(ClientPackets.CHANNEL_JOIN, stream.get())

def leave(self):
def leave(self) -> None:
"""Leave this channel"""
if not self.joined:
return
Expand All @@ -52,7 +52,7 @@ def leave(self):

self.game.bancho.enqueue(ClientPackets.CHANNEL_PART, stream.get())

def join_success(self):
def join_success(self) -> None:
"""Will be called by the server, when you successfully joined a channel"""
if not self.joined:
self.logger.info(f"Joined {self.name}!")
Expand All @@ -64,7 +64,7 @@ def join_success(self):
# Load players
self.game.bancho.players.load()

def send_message(self, message: str, force=False):
def send_message(self, message: str, force=False) -> None:
"""Send a message inside this channel
Args:
Expand Down
2 changes: 1 addition & 1 deletion osu/objects/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def by_name(self, name: str) -> Optional[Player]:
return p
return None

def load(self):
def load(self) -> None:
# Split players into chunks of 255
player_chunks = [
self.pending[i : i + 255] for i in range(0, len(self.pending), 255)
Expand Down
2 changes: 1 addition & 1 deletion osu/objects/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class Comment:
text: str

@classmethod
def from_string(cls, string: str):
def from_string(cls, string: str) -> "Comment":
line = string.split("\t")
return Comment(int(line[0]), CommentTarget(line[1]), line[2], line[3])
20 changes: 10 additions & 10 deletions osu/objects/player.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Set, List, Optional
from typing import Set, Optional

from .status import Status
from ..game import Game
Expand Down Expand Up @@ -61,6 +61,10 @@ def mode(self, value: Mode):
def loaded(self) -> bool:
return bool(self.name)

@property
def country(self) -> str:
return list(CountryCodes.keys())[self.country_code]

@property
def level(self) -> int:
if self.tscore <= 0:
Expand All @@ -75,23 +79,19 @@ def level(self) -> int:

return 1

@property
def country(self) -> str:
return list(CountryCodes.keys())[self.country_code]

def request_presence(self):
def request_presence(self) -> None:
"""Request a presence update for this player"""
self.game.bancho.request_presence([self.id])

def request_stats(self):
def request_stats(self) -> None:
"""Request a stats update for this player"""
self.game.bancho.request_stats([self.id])

def avatar(self) -> Optional[bytes]:
"""Get the avatar for this player"""
return self.game.api.get_avatar(self.id)

def send_message(self, message: str):
def send_message(self, message: str) -> None:
"""Send a PM to this player"""
if not (player := self.game.bancho.player):
return
Expand All @@ -113,7 +113,7 @@ def send_message(self, message: str):

self.game.bancho.enqueue(ClientPackets.SEND_PRIVATE_MESSAGE, stream.get())

def add_friend(self):
def add_friend(self) -> None:
"""Add this player to the friends list"""
if self.id in self.game.bancho.friends:
self.game.logger.warning(
Expand All @@ -128,7 +128,7 @@ def add_friend(self):
ClientPackets.FRIEND_ADD, int(self.id).to_bytes(4, "little")
)

def remove_friend(self):
def remove_friend(self) -> None:
"""Remove this player from the friends list"""
if self.id not in self.game.bancho.friends:
self.game.logger.warning(
Expand Down
4 changes: 2 additions & 2 deletions osu/objects/replays.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def encode(self) -> bytes:
return stream.get()

@classmethod
def decode(cls, stream: StreamIn):
def decode(cls, stream: StreamIn) -> "ReplayFrame":
button_state = ButtonState(stream.u8())

# This byte is now unused and was replaced by the ButtonState flag
Expand Down Expand Up @@ -84,7 +84,7 @@ def encode(self) -> bytes:
return stream.get()

@classmethod
def decode(cls, stream: StreamIn):
def decode(cls, stream: StreamIn) -> "ScoreFrame":
return ScoreFrame(
stream.s32(),
stream.u8(),
Expand Down
4 changes: 2 additions & 2 deletions osu/objects/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Score:
has_replay: bool

@classmethod
def from_string(cls, string: str, mode: Mode):
def from_string(cls, string: str, mode: Mode) -> "Score":
lines = string.split("|")

return Score(
Expand Down Expand Up @@ -70,7 +70,7 @@ class ScoreResponse:
scores: List[Score]

@classmethod
def from_string(cls, string: str, mode: Mode):
def from_string(cls, string: str, mode: Mode) -> "ScoreResponse":
result = string.split("\n")

if len(result) <= 0:
Expand Down

0 comments on commit bd1cc0a

Please sign in to comment.