Repository navigation
Conversation
|
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/3435/head:pr-3435
git checkout pr-3435This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/3435/head |
First rough sweep up to line 1350 fixing what I could
|
For context, I'm trying to stay in |
|
I've done my best and killed over 200 type errors, with a sad 396 left. There are many things that are definitely too complex for me / requiring better lib knowledge, as well as a couple of things we seem to lack data dicts for. You'll see those for yourself if you run basedpyright over this horrible file. |
plun1331
left a comment
There was a problem hiding this comment.
i know its not in the pr but:
state 786 has a typing error (and probably just doesn't work at all)
1246 is mad about something
overload for request_guild_channel_info needs to be fixed to include a default
probably a few other things
| def parse_guild_member_remove(self, data) -> None: | ||
| def parse_guild_member_remove(self, data: MemberRemoveEventPayload) -> None: | ||
| user = self.store_user(data["user"]) | ||
| raw = RawMemberRemoveEvent(data, user) |
There was a problem hiding this comment.
change the type for this to also include member
There was a problem hiding this comment.
If I change it in RawMemberRemoveEvent i get all sorts of new errors in that file, not doing that in this PR
| @@ -1680,6 +1786,8 @@ def parse_guild_audit_log_entry_create(self, data) -> None: | |||
| payload = RawAuditLogEntryEvent(data) | |||
| payload.guild = guild | |||
There was a problem hiding this comment.
probably make guild a possible attr on this event
There was a problem hiding this comment.
Added it only to its slots, ig thats enough
| else guild.get_member(data.get("creator_id")) | ||
| ) | ||
| creator = None | ||
| if data.get("creator"): |
There was a problem hiding this comment.
typeddict is wrong here, creator is NotRequired
There was a problem hiding this comment.
(A TypedDict with 5 required fields is always truthy: Inferred type User is always truthytyredundant-condition)
|
Addressed all comments, only resolved the ones I felt confident in, please check yourself what you consider resolved |
There was a problem hiding this comment.
278:65 error [reportArgumentType]
Argument of type "ChannelFlags | Any | int" cannot be assigned to parameter "value" of type "int" in function "_from_value"
Type "ChannelFlags | Any | int" is not assignable to type "int"
"ChannelFlags" is not assignable to "int"
New issue in this file
There was a problem hiding this comment.
@Paillat-dev Flags are a GIGANTIC mess imho, the built-in class seems to confuse the typechecker hella and the lib can't agree on whether to type them as ints or xFlag classes
| ) | ||
| ) | ||
| member, before, after = guild._update_voice_state(data, channel_id) # type: ignore | ||
| if not isinstance(channel_id, int): |
There was a problem hiding this comment.
When someone leaves voice, channel_id IS None so this should most likely not return early
| self._stickers.pop(emoji.id, None) | ||
| # guild won't be None here | ||
| guild.stickers = tuple( | ||
| map(lambda d: self.store_sticker(guild, d), data["stickers"]) |
There was a problem hiding this comment.
1614:57 error [reportGeneralTypeIssues]
Could not access item in TypedDict
"stickers" is not a defined key in "GuildSticker"
P sure your typing above is not right, for data.
| def _add_reaction( | ||
| self, | ||
| data: ReactionPayload, | ||
| emoji: PartialEmoji | GuildEmoji | AppEmoji | str | None, | ||
| user_id: int, | ||
| ) -> Reaction: |
There was a problem hiding this comment.
This causes a new issue in state.py:
1027:46 error [reportArgumentType]
Argument of type "ReactionActionEvent" cannot be assigned to parameter "data" of type "Reaction" in function "_add_reaction"
"count" is missing from "ReactionActionEvent"
"me" is missing from "ReactionActionEvent"
"me_burst" is missing from "ReactionActionEvent"
"count_details" is missing from "ReactionActionEvent"
| def store_emoji(self, guild: Guild, data: EmojiPayload) -> GuildEmoji | None: | ||
| # the id will be present here | ||
| emoji_id = int(data["id"]) # type: ignore | ||
| if data["id"] is None: | ||
| _log.warning("Received emoji without id") | ||
| return None | ||
| emoji_id = int(data["id"]) | ||
| self._emojis[emoji_id] = emoji = GuildEmoji(guild=guild, state=self, data=data) | ||
| return emoji |
There was a problem hiding this comment.
Causing new issues in multiple files:
guild.py:
615:47 error [reportAttributeAccessIssue]
Cannot assign to attribute "emojis" for class "Guild*"
"tuple[GuildEmoji | None, ...]" is not assignable to "tuple[GuildEmoji, ...]"
Tuple entry 1 is incorrect type
Type "GuildEmoji | None" is not assignable to type "GuildEmoji"
"None" is not assignable to "GuildEmoji"
3295:16 error [reportReturnType]
Type "GuildEmoji | None" is not assignable to return type "GuildEmoji"
Type "GuildEmoji | None" is not assignable to type "GuildEmoji"
"None" is not assignable to "GuildEmoji"
state.py
1594:24 error [reportAttributeAccessIssue]
Cannot assign to attribute "emojis" for class "Guild"
"tuple[GuildEmoji | None, ...]" is not assignable to "tuple[GuildEmoji, ...]"
Tuple entry 1 is incorrect type
Type "GuildEmoji | None" is not assignable to type "GuildEmoji"
"None" is not assignable to "GuildEmoji"
| def get_reaction_emoji( | ||
| self, data: PartialEmojiPayload | ||
| ) -> GuildEmoji | AppEmoji | PartialEmoji | str | None: | ||
| emoji_id = utils._get_as_snowflake(data, "id") |
There was a problem hiding this comment.
This causes a new issue in reaction.py
106:66 error [reportAttributeAccessIssue]
Cannot assign to attribute "emoji" for class "Reaction*"
Type "PartialEmoji | GuildEmoji | AppEmoji | str | None" is not assignable to type "PartialEmoji | GuildEmoji | AppEmoji | str"
Type "None" is not assignable to type "PartialEmoji | GuildEmoji | AppEmoji | str"
"None" is not assignable to "PartialEmoji"
"None" is not assignable to "GuildEmoji"
"None" is not assignable to "AppEmoji"
"None" is not assignable to "str"
Summary
Just a best-effort attempt at trying to improve typing in this file. Goal is to improve, not fix everything, that would need way too many changes across too many files.
Method of the madness: Installed basedpyright, then just went from the top to the bottom of the file
Information
examples, ...).
Checklist
type: ignorecomments were used, a comment is also left explaining why.