fix(typing): Message.topic also holds a DirectMessagesTopic - #368
Open
Danipulok wants to merge 1 commit into
Open
fix(typing): Message.topic also holds a DirectMessagesTopic#368Danipulok wants to merge 1 commit into
Message.topic also holds a DirectMessagesTopic#368Danipulok wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Message.topicis annotatedOptional["types.ForumTopic"]atmessage.py:655, and in achannel direct-messages chat it holds a
DirectMessagesTopic.message.py:1870, in thebranch guarded by
chat.type == enums.ChatType.DIRECT:The cache branch a few lines above it does the same. So reading
message.topic.icon_colorafter a
ForumTopic-shaped check passes the type checker and raises at runtime in a directchat, and the honest code — checking which of the two it is — is reported as unreachable.
The change
The annotation, and the docstring entry that describes it:
I took the assignment as correct and the annotation as the thing that was behind — the
direct-messages topic is a real, separate type with its own fetch method, so narrowing the
other way would mean deciding that
message.py:1870is the bug. If you would rather it wentthat way, say so and I will redo it.