Skip to content

Fix invalid-return-type errors in story methods#89

Merged
5hojib merged 1 commit intobetafrom
fix-ty-invalid-return-type-18332863698508062462
Feb 21, 2026
Merged

Fix invalid-return-type errors in story methods#89
5hojib merged 1 commit intobetafrom
fix-ty-invalid-return-type-18332863698508062462

Conversation

@5hojib
Copy link
Member

@5hojib 5hojib commented Feb 21, 2026

This change addresses the invalid-return-type category of errors reported by the ty type checker. Specifically, it updates the type hints for story-related methods in pyrogram/methods/stories/get_stories.py and pyrogram/types/messages_and_media/message_story.py to include StorySkipped and StoryDeleted in 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:

  • Update MessageStory._parse return annotation to include skipped and deleted story variants and lists thereof.
  • Update get_stories method return annotation to cover skipped and deleted stories alongside existing story types.

…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.
@google-labs-jules
Copy link
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 21, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates 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 types

classDiagram
    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
Loading

File-Level Changes

Change Details Files
Broaden story parsing helper return type to reflect all possible story variants produced by the underlying parsing logic.
  • Expand _parse() return type union to include StorySkipped and StoryDeleted alongside Story and MessageStory.
  • Allow _parse() to return lists containing Story, StorySkipped, and StoryDeleted elements instead of lists restricted to Story only.
  • Keep the runtime logic intact; only the type signature is adjusted to match existing behavior.
pyrogram/types/messages_and_media/message_story.py
Broaden public get_stories() method return type to cover skipped and deleted stories.
  • Extend get_stories() return union to include StorySkipped and StoryDeleted in single-object results.
  • Update list return type so it can contain Story, StorySkipped, and StoryDeleted items.
  • Align the public API’s type hints with the underlying story parsing and returned objects to satisfy the type checker.
pyrogram/methods/stories/get_stories.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 invalid-return-type errors reported by the ty type checker by enhancing the type hints for methods that handle story objects. The changes ensure that the declared return types accurately reflect the possible StorySkipped and StoryDeleted objects that can be returned, improving type safety and code correctness within the Pyrogram library.

Highlights

  • Type Hint Correction: Updated return type annotations for story-related methods (get_stories and _parse) to explicitly include StorySkipped and StoryDeleted types, resolving invalid-return-type errors.
Changelog
  • pyrogram/methods/stories/get_stories.py
    • Expanded the return type hint for the get_stories method to include types.StorySkipped and types.StoryDeleted as possible return types, both individually and within a list.
  • pyrogram/types/messages_and_media/message_story.py
    • Extended the return type hint for the _parse method to account for types.StorySkipped and types.StoryDeleted as potential return values, either directly or within a list.
Activity
  • The pull request was automatically created by Jules for a task initiated by @5hojib.
  • All tests passed successfully before submission.
  • Temporary log files were removed prior to the PR being opened.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +20 to +26
) -> (
types.Story
| types.StorySkipped
| types.StoryDeleted
| list[types.Story | types.StorySkipped | types.StoryDeleted]
| None
):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.StoryDeleted

Then the return type can be simplified to:
-> StoryItem | list[StoryItem] | None

Comment on lines +39 to +46
) -> (
MessageStory
| types.Story
| types.StorySkipped
| types.StoryDeleted
| list[types.Story | types.StorySkipped | types.StoryDeleted]
| None
):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.StoryDeleted

Then, this signature could be simplified to:
-> MessageStory | StoryItem | list[StoryItem] | None

@5hojib 5hojib merged commit 553b164 into beta Feb 21, 2026
1 check passed
@5hojib 5hojib deleted the fix-ty-invalid-return-type-18332863698508062462 branch February 21, 2026 16:19
5hojib added a commit that referenced this pull request Feb 22, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant