Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #596

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:

repos:
- repo: https://github.com/psf/black
rev: 24.10.0
rev: 25.1.0
hooks:
- id: black

Expand All @@ -14,7 +14,7 @@ repos:
args: [--line-length=120, --target-version=py310]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
rev: v0.11.4
hooks:
- id: ruff
args: [--fix]
12 changes: 6 additions & 6 deletions steam/_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def json_dumps(
return __decoder(__func(obj))


JSON_LOADS: Final = cast(Callable[[str | bytes], Any], json_loads)
JSON_LOADS: Final = cast("Callable[[str | bytes], Any]", json_loads)
JSON_DUMPS: Final = json_dumps


Expand Down Expand Up @@ -109,8 +109,8 @@ def vdf_binary_loads(
vdf_loads = orvdf.loads # type: ignore
vdf_binary_loads = orvdf.binary_loads # type: ignore

VDF_LOADS: Final = cast(Callable[[str], VDFDict], vdf_loads)
VDF_BINARY_LOADS: Final = cast(Callable[[bytes], BinaryVDFDict], vdf_binary_loads)
VDF_LOADS: Final = cast("Callable[[str], VDFDict]", vdf_loads)
VDF_BINARY_LOADS: Final = cast("Callable[[bytes], BinaryVDFDict]", vdf_binary_loads)

HTML_PARSER: Final = "lxml-xml" if importlib.util.find_spec("lxml") else "html.parser"

Expand All @@ -125,17 +125,17 @@ def vdf_binary_loads(


def READ_U32(
s: Buffer, unpacker: Callable[[Buffer], tuple[int]] = cast(Any, struct.Struct("<I").unpack_from), /
s: Buffer, unpacker: Callable[[Buffer], tuple[int]] = cast("Any", struct.Struct("<I").unpack_from), /
) -> int:
(u32,) = unpacker(s)
return u32


WRITE_U32: Final = cast(Callable[[int], bytes], struct.Struct("<I").pack)
WRITE_U32: Final = cast("Callable[[int], bytes]", struct.Struct("<I").pack)

_PROTOBUF_MASK: Final = 0x80000000
# inlined as these are some of the most called functions in the library
IS_PROTO: Final = cast(Callable[[int], bool], _PROTOBUF_MASK.__and__) # this is boolean like for a bit of extra speed
IS_PROTO: Final = cast("Callable[[int], bool]", _PROTOBUF_MASK.__and__) # this is boolean like for a bit of extra speed
SET_PROTO_BIT: Final = _PROTOBUF_MASK.__or__
CLEAR_PROTO_BIT: Final = (~_PROTOBUF_MASK).__and__

Expand Down
2 changes: 1 addition & 1 deletion steam/_gc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init_subclass__(cls) -> None:
bases = [base for base in cls.__mro__ if issubclass(base, Client) and base is not Client]
previous_state = None
cls._GC_BASES = cast( # type: ignore
tuple[type[GCState[Any]], ...],
"tuple[type[GCState[Any]], ...]",
tuple(
dict.fromkeys(
previous_state := get_annotations(base, eval_str=True).get("_state", previous_state)
Expand Down
2 changes: 1 addition & 1 deletion steam/_gc/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init_subclass__(cls) -> None:
@property
def backpack(self) -> Inv | None:
try:
return cast(Inv, self.backpacks[APP.get().id])
return cast("Inv", self.backpacks[APP.get().id])
except KeyError:
return None

Expand Down
4 changes: 2 additions & 2 deletions steam/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,9 +1012,9 @@ async def fetch_message(self, id: int, /) -> MessageT | None:
@dataclass(slots=True)
class Channel(Messageable[MessageT], Generic[MessageT, ClanT, GroupT]):
_state: ConnectionState
clan: ClanT = cast(ClanT, None)
clan: ClanT = cast("ClanT", None)
"""The clan this channel belongs to."""
group: GroupT = cast(GroupT, None)
group: GroupT = cast("GroupT", None)
"""The group this channel belongs to."""


Expand Down
4 changes: 2 additions & 2 deletions steam/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,12 @@ def __init__(
self.class_ = data["class"]
"""Extra info about the item."""
self.prices = cast(
Mapping[Currency, int],
"Mapping[Currency, int]",
{Currency.try_name(name): price for name, price in data["prices"].items()},
)
"""The prices of the asset in the store."""
self.original_prices = cast(
Mapping[Currency, int] | None,
"Mapping[Currency, int] | None",
(
{
Currency.try_name(name): price
Expand Down
12 changes: 6 additions & 6 deletions steam/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def __init__(
self, state: ConnectionState, chat_group: ChatGroup[Any, Any], user: User | ClientUser, member: chat.Member
) -> None:
super().__init__(state, user)
self.clan = cast(ClanT, None)
self.group = cast(GroupT, None)
self.clan = cast("ClanT", None)
self.group = cast("GroupT", None)

self._update(member)

Expand Down Expand Up @@ -214,7 +214,7 @@ def __init__(self, proto: chat.IncomingChatMessageNotification, channel: ChatT,
super().__init__(channel, proto)
self.author = author
self.created_at = DateTime.from_timestamp(proto.timestamp)
self._mentions_ids = cast(tuple[ID32, ...], tuple(proto.mentions.ids))
self._mentions_ids = cast("tuple[ID32, ...]", tuple(proto.mentions.ids))
self.mentions_all = proto.mentions.mention_all
self.mentions_here = proto.mentions.mention_here

Expand Down Expand Up @@ -554,7 +554,7 @@ async def _from_proto(
self._id = ChatGroupID(proto.chat_group_id)
self.active_member_count = proto.active_member_count
self._owner_id = ID32(proto.accountid_owner)
self._top_members = cast(list[ID32], proto.top_members)
self._top_members = cast("list[ID32]", proto.top_members)
self.tagline = proto.chat_group_tagline
self.app = PartialApp(state, id=proto.appid) if proto.appid else self.app
self._avatar_sha = proto.chat_group_avatar_sha
Expand Down Expand Up @@ -632,7 +632,7 @@ def _update_header_state(self, proto: chat.GroupHeaderState, /) -> None:

def _update_group_state(self, group_state: chat.GroupState):
self._partial_members = cast(
dict[ID32, chat.Member], {member.accountid: member for member in group_state.members}
"dict[ID32, chat.Member]", {member.accountid: member for member in group_state.members}
)
self._roles = {
RoleID(role.role_id): Role(self._state, self, role, permissions)
Expand Down Expand Up @@ -801,7 +801,7 @@ async def search(self, name: str) -> Sequence[MemberT]:
return [self._members[ID32(user.accountid)] for user in msg.matching_members]

return cast(
list[MemberT],
"list[MemberT]",
self._maybe_members(
user.id for user in [self._state._store_user(user.persona) for user in msg.matching_members]
),
Expand Down
6 changes: 3 additions & 3 deletions steam/clan.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ async def create_event(
if event.name != name or event.content != content:
continue
self._state.dispatch("event_create", event)
return cast(Event[CreateableEvents, Self], event)
return cast("Event[CreateableEvents, Self]", event)
raise ValueError

async def create_announcement(
Expand Down Expand Up @@ -378,15 +378,15 @@ async def _load(self, *, from_proto: bool = False) -> Self:
assert soup.title is not None
_, _, self.name = soup.title.text.rpartition(" :: ")
icon_url = soup.find("link", rel="image_src")
url = URL(cast(str, icon_url["href"])) if isinstance(icon_url, Tag) else None
url = URL(cast("str", icon_url["href"])) if isinstance(icon_url, Tag) else None
if url:
self._avatar_sha = bytes.fromhex(url.path.removesuffix("/").removesuffix("_full.jpg"))

headline = soup.find("div", class_="group_content group_summary")
headline_h1 = headline.h1 if isinstance(headline, Tag) else None
self.headline = headline_h1.text if headline_h1 else None
content = soup.find("meta", property="og:description")
self.summary = parse_bb_code(cast(str, content["content"])) if isinstance(content, Tag) else None
self.summary = parse_bb_code(cast("str", content["content"])) if isinstance(content, Tag) else None

if self._is_app_clan:
for entry in soup.find_all("div", class_="actionItem"):
Expand Down
4 changes: 2 additions & 2 deletions steam/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ async def throttle() -> None:
try:
async with timeout(60):
self.ws = cast(
SteamWebSocket,
"SteamWebSocket",
await login_func(
self,
*args,
Expand Down Expand Up @@ -1118,7 +1118,7 @@ async def fetch_published_files(
language
The language to fetch the published files in. If ``None``, the current language is used.
"""
return await self._state.fetch_published_files(cast(tuple[PublishedFileID, ...], ids), revision, language)
return await self._state.fetch_published_files(cast("tuple[PublishedFileID, ...]", ids), revision, language)

async def create_post(self, content: str, /, app: App | None = None) -> Post[ClientUser]:
"""Create a post.
Expand Down
6 changes: 3 additions & 3 deletions steam/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,10 @@ def from_web_api_str(cls, string: str, /) -> Language:


_REVERSE_API_LANGUAGE_MAP: Final = cast(
Mapping[str, Language], {value: key for key, value in Language.API_LANGUAGE_MAP.items()}
"Mapping[str, Language]", {value: key for key, value in Language.API_LANGUAGE_MAP.items()}
)
_REVERSE_WEB_API_MAP: Final = cast(
Mapping[str, Language], {value: key for key, value in Language.WEB_API_MAP.items()}
"Mapping[str, Language]", {value: key for key, value in Language.WEB_API_MAP.items()}
)


Expand Down Expand Up @@ -1513,7 +1513,7 @@ class DepotFileFlag(Flags):
"""A symlink file."""


TYPE_TRANSFORM_MAP: Final = cast(Mapping[str, str], {
TYPE_TRANSFORM_MAP: Final = cast("Mapping[str, str]", {
"Dlc": "DLC",
})

Expand Down
2 changes: 1 addition & 1 deletion steam/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, state: ConnectionState, clan: ClanT, data: clan.Event):
"""The event's description."""
self.app = PartialApp(state, id=data["appid"]) if data["appid"] else None
"""The app that the event is going to be played in."""
self.type = cast(EventTypeT, EventType.try_value(data["event_type"]))
self.type = cast("EventTypeT", EventType.try_value(data["event_type"]))
"""The event's type."""
self.clan = clan
"""The event's clan."""
Expand Down
2 changes: 1 addition & 1 deletion steam/ext/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ def decorator(callback: CoroFuncT) -> G:
attrs.setdefault("parent", self)
result = group(name=name, cls=cls or Group, **attrs)(callback)
self.add_command(result)
return cast(G, result) # casting shouldn't really be necessary
return cast("G", result) # casting shouldn't really be necessary

return decorator(callback) if callback is not None else decorator

Expand Down
6 changes: 3 additions & 3 deletions steam/ext/commands/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def source(ctx, command: commands.Command): # this then calls command_con

annotations = get_annotations(func)
converter_for = annotations["return"]
func = cast(BasicConverter[T], func)
func = cast("BasicConverter[T]", func)
func.converter_for = converter_for
CONVERTERS[converter_for].append(func)
return func
Expand Down Expand Up @@ -221,7 +221,7 @@ async def is_cool(ctx, user: steam.User): ...
(
command.special_converters
if isinstance(command, Command)
else cast(list[Converters], command.__special_converters__) # type: ignore
else cast("list[Converters]", command.__special_converters__) # type: ignore
).append(cls)
except AttributeError:
command.__special_converters__ = [cls] # type: ignore
Expand Down Expand Up @@ -531,4 +531,4 @@ def __class_getitem__(cls, converter: T | tuple[T]) -> Self:
if (isinstance(converter, type) and issubclass(converter, str)) or converter is types.NoneType:
raise TypeError(f"Greedy[{converter.__name__}] is invalid") # type: ignore

return cast(Self, GreedyGenericAlias(cls, (converter,)))
return cast("Self", GreedyGenericAlias(cls, (converter,)))
2 changes: 1 addition & 1 deletion steam/ext/commands/cooldown.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class BucketTypeType:
def __new__(cls, *values: int | None) -> Self:
return cast(Self, values)
return cast("Self", values)


class BucketType(IntEnum):
Expand Down
2 changes: 1 addition & 1 deletion steam/ext/commands/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HelpCommand(Command[None, ..., None]):
"""The context for the command's invocation."""

def __init__(self, **kwargs: Unpack[CommandKwargs]):
default = cast(CommandKwargs, {"name": "help", "help": "Shows this message."} | kwargs)
default = cast("CommandKwargs", {"name": "help", "help": "Shows this message."} | kwargs)
super().__init__(self.command_callback, **default)

async def invoke(self, ctx: Context) -> None:
Expand Down
4 changes: 2 additions & 2 deletions steam/ext/csgo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, state: GCState, match_info: cstrike.MatchInfo, players: dict[

self.rounds: list[Round] = []
for round in match_info.roundstatsall:
player_ids = cast(list[ID32], round.reservation.account_ids)
player_ids = cast("list[ID32]", round.reservation.account_ids)
team_size = len(player_ids) // len(round.team_scores)
previous_scores = [0] * len(round.team_scores)
teams: list[Team] = []
Expand Down Expand Up @@ -201,7 +201,7 @@ class MatchPlayer(PartialUser, user.WrapsUser): # type: ignore
mvp: bool


LEVEL_MAP: Final = cast(Mapping[int, str], {
LEVEL_MAP: Final = cast("Mapping[int, str]", {
0: "Not Recruited",
1: "Recruit", # 1-3
4: "Private", # 4-7 etc.
Expand Down
4 changes: 2 additions & 2 deletions steam/ext/csgo/protobufs/cstrike.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion steam/ext/csgo/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


def READ_F32(
bytes: bytes, *, _unpacker: Callable[[bytes], tuple[float]] = cast(Any, struct.Struct("<f").unpack_from)
bytes: bytes, *, _unpacker: Callable[[bytes], tuple[float]] = cast("Any", struct.Struct("<f").unpack_from)
) -> float:
(f32,) = _unpacker(bytes)
return f32
Expand Down
2 changes: 1 addition & 1 deletion steam/ext/csgo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Final, NamedTuple, cast

CHARS = cast(
Mapping[str, int], dict(zip("ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789", itertools.count()))
"Mapping[str, int]", dict(zip("ABCDEFGHJKLMNOPQRSTUVWXYZabcdefhijkmnopqrstuvwxyz23456789", itertools.count()))
)


Expand Down
2 changes: 1 addition & 1 deletion steam/game_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def where(cls, **kwargs: Unpack[QueryWhereKwargs]) -> str:
raise TypeError(f"{name!r} is an invalid keyword argument for where()") from None
metadata: tuple[Any, ...] = annotated.__metadata__
if name in QueryWhereBoolKwargs.__annotations__:
value = cast(bool, value)
value = cast("bool", value)
try:
filter_code = metadata[not value]
except IndexError:
Expand Down
4 changes: 2 additions & 2 deletions steam/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async def id64_from_url(url: StrOrURL, /, session: aiohttp.ClientSession | None
return id.id64 if id is not None else None


_ID64_TO_ID32: Final = cast(Callable[[int], ID32], 0xFFFFFFFF.__and__)
_ID64_TO_ID32: Final = cast("Callable[[int], ID32]", 0xFFFFFFFF.__and__)


TypeT = TypeVar("TypeT", bound=Type, default=Type, covariant=True)
Expand Down Expand Up @@ -281,7 +281,7 @@ def universe(self) -> Universe:
@property
def type(self) -> TypeT:
"""The Steam type of the ID."""
return cast(TypeT, Type.try_value((self.id64 >> 52) & 0xF))
return cast("TypeT", Type.try_value((self.id64 >> 52) & 0xF))

@property
def instance(self) -> Instance:
Expand Down
2 changes: 1 addition & 1 deletion steam/leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Leaderboard(Generic[AppT, DisplayNameT]):
"""The display type of the leaderboard."""
entry_count: int
"""The number of entries in the leaderboard."""
display_name: DisplayNameT = cast(DisplayNameT, None)
display_name: DisplayNameT = cast("DisplayNameT", None)
"""The display name of the leaderboard. This is only set if the leaderboard is fetched using :meth:`PartialApp.leaderboards`."""

def __repr__(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion steam/protobufs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
PROTOBUFS: Final = cast("Mapping[EMsg, type[ProtobufMessage | Message]]", {})
RequestType: TypeAlias = "type[UnifiedMessage]"
ResponseType: TypeAlias = "type[UnifiedMessage]"
UMS: Final = cast(Mapping[str, tuple[RequestType, ResponseType]], {})
UMS: Final = cast("Mapping[str, tuple[RequestType, ResponseType]]", {})
GC_PROTOBUFS: Final = cast("Mapping[AppID, Mapping[IntEnum, type[GCProtobufMessage | GCMessage]]]", {})

from .emsg import *
Expand Down
2 changes: 1 addition & 1 deletion steam/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _Reaction:

BASE_REACTION_URL: Final = "https://store.cloudflare.steamstatic.com/public/images/loyalty/reactions/{type}/{id}.png"
BASE_ECONOMY_URL: Final = URL("https://community.akamai.steamstatic.com/economy")
AWARD_ID_TO_NAME: Final = cast(Mapping[int, str], {
AWARD_ID_TO_NAME: Final = cast("Mapping[int, str]", {
1: "Deep Thoughts",
2: "Heartwarming",
3: "Hilarious",
Expand Down
Loading
Loading