Skip to content

Conversation

@5hojib
Copy link
Member

@5hojib 5hojib commented Feb 7, 2026

Summary by Sourcery

Update documentation build process to use uv-based workflows and simplify synchronous client utilities.

Enhancements:

  • Adjust emoji status parsing to support collectible emoji statuses and optional until dates while preserving raw data.
  • Simplify client run logic to always use asynchronous start/idle/stop flow and remove deprecated sync context management and run_sync utilities.
  • Tidy various small style and docstring formatting issues across filters, raw primitives, and type docstrings.
  • Import compose and idle directly from methods.utilities instead of the removed sync module.

Build:

  • Switch docs build script and GitHub workflows to use uv for Python setup, dependency sync, and Sphinx invocation.
  • Pin Sphinx version for docs extra to <8.0.0 and adjust Sphinx config paths for templates, static files, and LaTeX logo.

CI:

  • Update docs generation and format/test workflows to install Python via setup-python, install uv, and rely on uv sync and uv run instead of manual pip and tool management.

Chores:

  • Add uv.lock and update .gitignore accordingly.
  • Apply minor formatting tweaks for gzip-packed and string primitives.

5hojib and others added 4 commits January 31, 2026 06:46
Signed-off-by: 5hojib <yesiamshojib@gmail.com>
- Pin sphinx < 8.0.0 to fix compatibility issues with sphinx-immaterial.
- Update CI workflows and build scripts to use uv for dependency management.
- Fix docstring indentation errors in multiple files.
- Clean up docs/source/conf.py by removing non-existent paths.
- Update .gitignore to exclude build artifacts and generated RST files.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
* Make the library completely async and remove sync functions

- Deleted `pyrogram/sync.py` which handled automatic sync wrapping.
- Updated `pyrogram/__init__.py` to export `compose` and `idle` as async.
- Removed synchronous context managers (`__enter__`, `__exit__`) from `Client`.
- Removed `run_sync` utility from `Methods` and `utils`.
- Simplified `app.run()` to handle async methods only.
- Deleted synchronous usage documentation and updated references.

Co-authored-by: 5hojib <107526130+5hojib@users.noreply.github.com>

* Update docs/source/topics/scheduling.rst

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 7, 2026

Reviewer's Guide

Migrates documentation and CI tooling to use uv-based workflows, cleans up deprecated synchronous utilities in the client API, tightens Sphinx/docs configuration and dependencies, and fixes/extends several type-level and parsing details in pyrogram internals.

Sequence diagram for updated Client.run behavior without synchronous path

sequenceDiagram
    actor User
    participant App as ApplicationMain
    participant Client
    participant RunUtility as RunHelper

    User->>App: invoke_client_run(optional_coroutine)

    alt coroutine_provided
        App->>RunUtility: run(coroutine)
        RunUtility-->>App: coroutine_completed
    else no_coroutine_provided
        App->>RunUtility: run(Client.start())
        RunUtility-->>Client: start()
        Client-->>RunUtility: started

        App->>RunUtility: run(idle())
        RunUtility-->>RunUtility: wait_for_signals

        App->>RunUtility: run(Client.stop())
        RunUtility-->>Client: stop()
        Client-->>RunUtility: stopped
    end
Loading

Class diagram for updated Client utilities and EmojiStatus parsing

classDiagram
    class Client {
        +loop
        +__init__(...)
        +__aenter__() Client
        +__aexit__(*args) None
        +start() Client
        +stop() None
    }

    class Utilities {
        <<mixin>>
        +Run
        +Start
        +Stop
        +Restart
        +RemoveHandler
        +StopTransmissionError
        +MethodUnavailableError
    }

    class EmojiStatus {
        +client
        +custom_emoji_id int
        +until_date datetime
        +_raw raw_base_EmojiStatus
        +__init__(client, custom_emoji_id, until_date, _raw)
        +_parse(client, emoji_status) EmojiStatus
    }

    class RawBaseEmojiStatus {
    }

    class RawEmojiStatusCollectible {
        +document_id int
        +until int
    }

    class Utils {
        +timestamp_to_datetime(timestamp) datetime
    }

    Client ..|> Utilities

    EmojiStatus --> RawBaseEmojiStatus : wraps
    RawEmojiStatusCollectible --|> RawBaseEmojiStatus
    EmojiStatus --> RawEmojiStatusCollectible : _raw
    EmojiStatus --> Utils : uses
Loading

File-Level Changes

Change Details Files
Switch docs build pipeline from ad-hoc virtualenv usage to uv-based environment management and commands.
  • Replace manual VENV management and make venv/api steps with uv sync --extra docs in the docs build script
  • Run compiler scripts (api, errors, docs) and Sphinx via uv run instead of explicit venv python/sphinx executables
  • Adjust Sphinx configuration to use local _static only and drop custom templates and LaTeX logo
build-docs.sh
docs/source/conf.py
pyproject.toml
Update GitHub Actions workflows to standardize on Python 3.13 and uv, simplifying dependency installation and tooling invocation.
  • Add explicit Python 3.13 setup and uv installation to the docs generation workflow before running the build script
  • In the format_and_test workflow, replace manual pip/pytest/ruff tooling setup with uv sync --extra dev and uv run for ruff and pytest
.github/workflows/docs_gen.yml
.github/workflows/format_and_test.yml
Remove synchronous context/utility helpers from the client API, moving toward a purely async usage model.
  • Delete the synchronous Client.__enter__/__exit__ context manager to discourage sync context usage
  • Remove the run_sync helper and its method mixin from utilities, along with the pyrogram/sync.py module
  • Simplify the run utility to always treat self.start as async and avoid the sync start/stop path
  • Adjust top-level pyrogram exports to import compose and idle from async utilities instead of the removed sync module
pyrogram/client.py
pyrogram/methods/utilities/run.py
pyrogram/methods/utilities/__init__.py
pyrogram/utils.py
pyrogram/__init__.py
pyrogram/methods/utilities/run_sync.py
pyrogram/sync.py
docs/source/topics/synchronous.rst
Refine emoji status parsing and related type details for newer Telegram emoji status variants.
  • Extend EmojiStatus to keep a reference to the raw emoji status object via an internal _raw attribute
  • Handle raw.types.EmojiStatusCollectible instead of the previous EmojiStatusUntil type and make until_date parsing tolerant of missing timestamps
pyrogram/types/user_and_chats/emoji_status.py
Minor internal cleanup and formatting improvements across core primitives and type docs.
  • Tidy up GzipPacked.read and String.read to conform to style guidelines without changing behavior
  • Improve docstrings for several types (e.g., topic filter, CollectibleItemInfo, PaidMediaPreview, MessageReactor, FoundContacts) by adding spacing for Sphinx
  • Add a uv.lock file and adjust ignore/docs files as part of the uv-based tooling migration
pyrogram/raw/core/gzip_packed.py
pyrogram/raw/core/primitives/string.py
pyrogram/filters.py
pyrogram/types/bots_and_keyboards/collectible_item_info.py
pyrogram/types/business/paid_media_preview.py
pyrogram/types/messages_and_media/message_reactor.py
pyrogram/types/user_and_chats/found_contacts.py
uv.lock
.gitignore
docs/source/index.rst
docs/source/faq/socket-send-oserror-timeouterror-connection-lost-reset.rst
docs/source/topics/scheduling.rst

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 primarily focuses on a significant architectural shift by completely removing support for synchronous usage throughout the codebase and documentation. It also modernizes the project's documentation build process by integrating 'uv' for dependency management and execution, aiming for a more streamlined and consistent build environment. Additionally, the changes include minor code formatting improvements and an enhancement to the EmojiStatus type's data handling.

Highlights

  • Removal of Synchronous Usage: All synchronous usage features, utilities, and related documentation have been deprecated and removed, signifying a full transition to an asynchronous-only framework.
  • Documentation Build Process Migration to uv: The documentation build pipeline has been modernized by adopting 'uv' for dependency management and script execution, replacing traditional 'make' and 'pip' commands for a more efficient process.
  • Streamlined Sphinx Configuration: The Sphinx documentation configuration has been cleaned up by removing unused template and static file paths, as well as a LaTeX logo.
  • Enhanced EmojiStatus Type: The EmojiStatus type has been updated to include raw data and features improved parsing logic for until_date from various raw emoji status types.
  • Improved .gitignore: The .gitignore file has been updated to exclude common build artifacts, virtual environments, and Ruff cache directories.
Changelog
  • .gitignore
    • Added new entries for virtual environments (venv/, .venv/), documentation build artifacts (docs/build/, docs/source/api/, Electrogram-docs/), and Ruff cache (.ruff_cache/).
  • build-docs.sh
    • Replaced make venv and pip install with uv sync --extra docs.
    • Changed make api to (cd compiler/api && uv run python compiler.py).
    • Updated Python and Sphinx command executions to use uv run.
  • docs/source/conf.py
    • Removed ../resources/templates from templates_path.
    • Removed ../resources/static from html_static_path.
    • Removed latex_logo configuration.
  • docs/source/faq/socket-send-oserror-timeouterror-connection-lost-reset.rst
    • Removed advice related to synchronous usage, specifically 'Use Electrogram asynchronously in its intended way' and 'Use shorter non-asynchronous processing loops'.
  • docs/source/index.rst
    • Removed the 'topics/synchronous' entry from the documentation index.
  • docs/source/topics/scheduling.rst
    • Reworded the introductory paragraph to remove references to non-asynchronous contexts.
    • Removed 'Asynchronously' and 'Non-Asynchronously' subheadings.
    • Removed the entire 'Non-Asynchronously' code example.
  • docs/source/topics/synchronous.rst
    • Removed the entire documentation file dedicated to synchronous usage.
  • pyproject.toml
    • Pinned the sphinx dependency to <8.0.0.
  • pyrogram/init.py
    • Updated imports for compose and idle to reference their new locations within pyrogram.methods.utilities.
  • pyrogram/client.py
    • Removed the __enter__ and __exit__ methods, effectively deprecating synchronous context management for the Client.
  • pyrogram/filters.py
    • Added blank lines within the topic filter's docstring for improved readability.
  • pyrogram/methods/utilities/init.py
    • Removed the import and reference to RunSync.
  • pyrogram/methods/utilities/run.py
    • Removed the inspect import.
    • Simplified the main function logic by removing conditional paths for synchronous self.start() calls.
  • pyrogram/methods/utilities/run_sync.py
    • Removed the run_sync utility file entirely.
  • pyrogram/raw/core/gzip_packed.py
    • Applied minor formatting adjustments to the read method's return statement.
  • pyrogram/raw/core/primitives/string.py
    • Applied minor formatting adjustments (trailing comma) to the decode method.
  • pyrogram/sync.py
    • Removed the entire sync.py module, which contained async_to_sync wrapper logic.
  • pyrogram/types/bots_and_keyboards/collectible_item_info.py
    • Added a blank line within the docstring for improved readability.
  • pyrogram/types/business/paid_media_preview.py
    • Added a blank line within the docstring for improved readability.
  • pyrogram/types/messages_and_media/message_reactor.py
    • Added a blank line within the docstring for improved readability.
  • pyrogram/types/user_and_chats/emoji_status.py
    • Added _raw parameter to the __init__ method.
    • Refined the _parse method to consistently handle until_date and _raw for different EmojiStatus types.
  • pyrogram/types/user_and_chats/found_contacts.py
    • Added a blank line within the docstring for improved readability.
  • pyrogram/utils.py
    • Removed the TypeVar import.
    • Removed the run_sync asynchronous utility function.
Ignored Files
  • Ignored by pattern: .github/workflows/** (2)
    • .github/workflows/docs_gen.yml
    • .github/workflows/format_and_test.yml
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 found 1 issue, and left some high level feedback:

  • The changes in pyrogram/methods/utilities/run.py remove the sync start() path and now always treat self.start as async, which will break existing synchronous usage of Client.run(); consider keeping a branch for non-coroutine start() or clearly migrating callers before this change.
  • In EmojiStatus._parse, the second isinstance check was changed from EmojiStatusUntil to EmojiStatusCollectible, which looks like it drops support for EmojiStatusUntil; please double‑check whether both variants need to be handled and adjust the branching accordingly.
  • Removing run_sync (and the sync context manager on Client) is an API change; if any internal or external callers still rely on those sync helpers, you may want to provide a compatibility shim or an explicit migration path to the async equivalents.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The changes in `pyrogram/methods/utilities/run.py` remove the sync `start()` path and now always treat `self.start` as async, which will break existing synchronous usage of `Client.run()`; consider keeping a branch for non-coroutine `start()` or clearly migrating callers before this change.
- In `EmojiStatus._parse`, the second `isinstance` check was changed from `EmojiStatusUntil` to `EmojiStatusCollectible`, which looks like it drops support for `EmojiStatusUntil`; please double‑check whether both variants need to be handled and adjust the branching accordingly.
- Removing `run_sync` (and the sync context manager on `Client`) is an API change; if any internal or external callers still rely on those sync helpers, you may want to provide a compatibility shim or an explicit migration path to the async equivalents.

## Individual Comments

### Comment 1
<location> `build-docs.sh:3-7` </location>
<code_context>
-VENV="$(pwd)/venv"
-export VENV
+
+uv sync --extra docs

 make clean
</code_context>

<issue_to_address>
**suggestion:** Relying on `uv` in the build script can make local docs building fail if `uv` is not installed.

In CI, `uv` is provisioned by the workflow, but locally this script now assumes `uv` is installed and on PATH. Please add a check that emits a clear error if `uv` is missing, or fall back to the previous venv-based flow when `uv` is not available so local doc builds remain robust for contributors.

```suggestion
set -e

export GITHUB_TOKEN

if ! command -v uv >/dev/null 2>&1; then
  echo "Error: 'uv' is required to build the documentation. Please install 'uv' or run this script from an environment where it is available on PATH." >&2
  exit 1
fi

uv sync --extra docs
```
</issue_to_address>

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.

Comment on lines 3 to +7
set -e

export GITHUB_TOKEN
VENV="$(pwd)/venv"
export VENV

uv sync --extra docs
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Relying on uv in the build script can make local docs building fail if uv is not installed.

In CI, uv is provisioned by the workflow, but locally this script now assumes uv is installed and on PATH. Please add a check that emits a clear error if uv is missing, or fall back to the previous venv-based flow when uv is not available so local doc builds remain robust for contributors.

Suggested change
set -e
export GITHUB_TOKEN
VENV="$(pwd)/venv"
export VENV
uv sync --extra docs
set -e
export GITHUB_TOKEN
if ! command -v uv >/dev/null 2>&1; then
echo "Error: 'uv' is required to build the documentation. Please install 'uv' or run this script from an environment where it is available on PATH." >&2
exit 1
fi
uv sync --extra docs

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 introduces significant and positive changes. The primary change is the removal of synchronous support, which simplifies the library's architecture and encourages the use of its asynchronous nature, which is the intended way. This breaking change is handled well, with corresponding updates to documentation, examples, and internal logic. The migration of the documentation build process and CI workflows to use uv is a great modernization step that simplifies dependency management and execution. Additionally, the adjustments to emoji status parsing to support collectible statuses and optional dates are valuable enhancements. The various minor formatting and docstring fixes across the codebase contribute to better readability and maintainability. Overall, this is a high-quality pull request with well-thought-out changes.

Signed-off-by: 5hojib <yesiamshojib@gmail.com>
Signed-off-by: 5hojib <yesiamshojib@gmail.com>
@5hojib 5hojib merged commit e845fe2 into dev Feb 8, 2026
2 checks passed
@5hojib 5hojib deleted the test branch February 8, 2026 12:04
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