Fix invalid-return-type errors in story methods#89
Conversation
…eted types Updated `get_stories` and `MessageStory._parse` to correctly reflect that they can return `StorySkipped` and `StoryDeleted` types, resolving `invalid-return-type` errors reported by the `ty` type checker.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates story-related method return type annotations to include StorySkipped and StoryDeleted, aligning type hints with the actual parsed/returned values and resolving invalid-return-type errors from the type checker. Class diagram for updated story-related return typesclassDiagram
class MessageStory {
+async _parse(client, message_story) MessageStory | Story | StorySkipped | StoryDeleted | list~Story | StorySkipped | StoryDeleted~ | None
}
class Client {
+async get_stories(chat_id, story_ids) Story | StorySkipped | StoryDeleted | list~Story | StorySkipped | StoryDeleted~ | None
}
class Story
class StorySkipped
class StoryDeleted
Client --> Story
Client --> StorySkipped
Client --> StoryDeleted
MessageStory --> Story
MessageStory --> StorySkipped
MessageStory --> StoryDeleted
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello @5hojib, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The expanded return type unions are getting quite verbose and duplicated between
MessageStory._parseandget_stories; consider introducing aStoryResult(or similar)TypeAliasto centralize and simplify these annotations.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The expanded return type unions are getting quite verbose and duplicated between `MessageStory._parse` and `get_stories`; consider introducing a `StoryResult` (or similar) `TypeAlias` to centralize and simplify these annotations.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request correctly addresses invalid-return-type errors by expanding the return type hints for get_stories and MessageStory._parse to include all possible story-related return types (StorySkipped, StoryDeleted). The changes are accurate and fix the type checking issues. I've added a couple of suggestions to introduce a type alias for these complex union types, which would improve code readability and maintainability.
| ) -> ( | ||
| types.Story | ||
| | types.StorySkipped | ||
| | types.StoryDeleted | ||
| | list[types.Story | types.StorySkipped | types.StoryDeleted] | ||
| | None | ||
| ): |
There was a problem hiding this comment.
To improve readability and maintainability, consider defining a type alias for the story types. This will make the complex return type annotation more concise and easier to manage, especially since it's used in multiple places.
You can define the alias inside the if TYPE_CHECKING: block at the top of the file:
from typing import TypeAlias
StoryItem: TypeAlias = types.Story | types.StorySkipped | types.StoryDeletedThen the return type can be simplified to:
-> StoryItem | list[StoryItem] | None
| ) -> ( | ||
| MessageStory | ||
| | types.Story | ||
| | types.StorySkipped | ||
| | types.StoryDeleted | ||
| | list[types.Story | types.StorySkipped | types.StoryDeleted] | ||
| | None | ||
| ): |
There was a problem hiding this comment.
This type hint has become quite long. To improve readability and reusability, consider using a type alias for the common story types, as suggested for the other file. This would be especially beneficial as this complex type is used in multiple method signatures.
You could define a StoryItem alias at the top of this module within a TYPE_CHECKING block:
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import TypeAlias
StoryItem: TypeAlias = types.Story | types.StorySkipped | types.StoryDeletedThen, this signature could be simplified to:
-> MessageStory | StoryItem | list[StoryItem] | None
…stness * fix(types): update story return type hints to include Skipped and Deleted types (#89) Updated `get_stories` and `MessageStory._parse` to correctly reflect that they can return `StorySkipped` and `StoryDeleted` types, resolving `invalid-return-type` errors reported by the `ty` type checker. * Fix unknown-argument type errors (#90) * Fix unknown-argument type errors This commit resolves all "unknown-argument" errors reported by the ty type checker. Key changes include: - Fixed Star Gift related methods in business methods to use correct raw API parameters and types. - Updated account.UpdateColor call to use PeerColor object. - Switched to messages.DeleteScheduledMessages for scheduled message deletion. - Removed unsupported parameters in send_media_group and send_paid_media. - Fixed CallbackQuery.edit_message_caption to call correct client methods and accept business_connection_id. - Removed unused/incorrect parameters in DraftMessage and get_chat calls. * InkyPinkyPonky [no ci] Signed-off-by: 5hojib <yesiamshojib@gmail.com> * update draft_message.py * fix: resolve `invalid-return-type` and `invalid-assignment` type errors (#91) This commit addresses several type errors reported by the `ty` type checker: - Fixed `invalid-return-type` in ## Summary by Sourcery Align Pyrogram with recent Telegram API changes, improve type handling and robustness, and fix various edge-case bugs across messages, chats, stories, and business payments. Bug Fixes: - Correct type hint generation for flags and raw base types in the compiler. - Avoid None-related errors when accessing message entities, quote entities, users, chats, and approvers in various parsers. - Ensure global hashtag search pagination uses the correct offset field and avoid misuse of channel IDs when handling updates. - Fix deletion of scheduled messages to use the proper API and return the correct identifiers. - Prevent attribute errors when parsing reaction counts with missing reactions and when saving files without an existing file_id. - Guard giveaway parsing to only handle giveaway media messages and support None chats in chat parsing and join requests. - Avoid errors in chat joiner parsing when approved_by is None and support None invites in chat invite link parsing. Enhancements: - Refine message parsing and serialization, including safer handling of text, entities, and reply buttons in Message and CallbackQuery operations. - Broaden story and story message parsing to support skipped and deleted stories in both return types and parser logic. - Update chat color changes to use the newer PeerColor structure for profile colors. - Improve type signatures and defaults for edit_message_caption and edit_message_media to better reflect optional invert_media behavior. - Simplify and clarify variable usage in several methods (e.g., packing auth data, custom emoji retrieval, and copy_message). Build: - Relax type checker configuration by ignoring invalid-assignment diagnostics. Documentation: - Document the new business_connection_id parameter in callback query text editing. Chores: - Update business payments and gifts methods to use the latest Telegram star gift API endpoints and parameter structures. --------- Signed-off-by: 5hojib <yesiamshojib@gmail.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This change addresses the
invalid-return-typecategory of errors reported by thetytype checker. Specifically, it updates the type hints for story-related methods inpyrogram/methods/stories/get_stories.pyandpyrogram/types/messages_and_media/message_story.pyto includeStorySkippedandStoryDeletedin their return unions, matching the actual types returned by the underlying parsing logic. All tests passed and temporary log files were removed before submission.PR created automatically by Jules for task 18332863698508062462 started by @5hojib
Summary by Sourcery
Align story-related return type hints with the actual parsed story variants to satisfy static type checking.
Bug Fixes: