From 9e55737ab27bec7d0b6a505f530addec078c4651 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:13:22 +0200 Subject: [PATCH 1/5] Use a Composite Action for Testing Type Completeness --- .github/workflows/type_completeness.yml | 65 ++----------------------- 1 file changed, 4 insertions(+), 61 deletions(-) diff --git a/.github/workflows/type_completeness.yml b/.github/workflows/type_completeness.yml index 4a98c0b30a8..17dc249c81f 100644 --- a/.github/workflows/type_completeness.yml +++ b/.github/workflows/type_completeness.yml @@ -4,6 +4,7 @@ on: paths: - telegram/** - pyproject.toml + - .github/workflows/type_completeness.yml push: branches: - master @@ -13,66 +14,8 @@ jobs: name: test-type-completeness runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - run: git fetch --depth=1 # https://github.com/actions/checkout/issues/329#issuecomment-674881489 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + - uses: Bibo-Joshi/pyright-type-completeness@1.0.0 with: + package-name: telegram python-version: 3.12 - cache: 'pip' - cache-dependency-path: '**/requirements*.txt' - - name: Install Pyright - run: | - python -W ignore -m pip install pyright~=1.1.367 - - name: Get PR Completeness - # Must run before base completeness, as base completeness will checkout the base branch - # And we can't go back to the PR branch after that in case the PR is coming from a fork - run: | - pip install . -U - pyright --verifytypes telegram --ignoreexternal --outputjson > pr.json || true - pyright --verifytypes telegram --ignoreexternal > pr.readable || true - - name: Get Base Completeness - run: | - git checkout ${{ github.base_ref }} - pip install . -U - pyright --verifytypes telegram --ignoreexternal --outputjson > base.json || true - - name: Compare Completeness - uses: jannekem/run-python-script-action@v1 - with: - script: | - import json - import os - from pathlib import Path - - base = float( - json.load(open("base.json", "rb"))["typeCompleteness"]["completenessScore"] - ) - pr = float( - json.load(open("pr.json", "rb"))["typeCompleteness"]["completenessScore"] - ) - base_text = f"This PR changes type completeness from {round(base, 3)} to {round(pr, 3)}." - - if base == 0: - text = f"Something is broken in the workflow. Reported type completeness is 0. 💥" - set_summary(text) - print(Path("pr.readable").read_text(encoding="utf-8")) - error(text) - exit(1) - - if pr < (base - 0.001): - text = f"{base_text} ❌" - set_summary(text) - print(Path("pr.readable").read_text(encoding="utf-8")) - error(text) - exit(1) - elif pr > (base + 0.001): - text = f"{base_text} ✨" - set_summary(text) - if pr < 1: - print(Path("pr.readable").read_text(encoding="utf-8")) - print(text) - else: - text = f"{base_text} This is less than 0.1 percentage points. ✅" - set_summary(text) - print(Path("pr.readable").read_text(encoding="utf-8")) - print(text) + pyright-version: ~=1.1.367 From 8b9d55f7901c2a81f83c99389df5de92efe8b67f Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:27:05 +0200 Subject: [PATCH 2/5] Temporarily decrease type completeness for demonstration --- telegram/ext/_application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram/ext/_application.py b/telegram/ext/_application.py index 4f623ed3695..17d2b06e4e3 100644 --- a/telegram/ext/_application.py +++ b/telegram/ext/_application.py @@ -319,7 +319,7 @@ def __init__( stacklevel=2, ) - self.bot: BT = bot + self.bot = bot self.update_queue: asyncio.Queue[object] = update_queue self.context_types: ContextTypes[CCT, UD, CD, BD] = context_types self.updater: Optional[Updater] = updater From b22ced13a19f639b16c69065835f678fac9a2180 Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:29:40 +0200 Subject: [PATCH 3/5] Revert "Temporarily decrease type completeness for demonstration" This reverts commit 8b9d55f7901c2a81f83c99389df5de92efe8b67f. --- telegram/ext/_application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram/ext/_application.py b/telegram/ext/_application.py index 17d2b06e4e3..4f623ed3695 100644 --- a/telegram/ext/_application.py +++ b/telegram/ext/_application.py @@ -319,7 +319,7 @@ def __init__( stacklevel=2, ) - self.bot = bot + self.bot: BT = bot self.update_queue: asyncio.Queue[object] = update_queue self.context_types: ContextTypes[CCT, UD, CD, BD] = context_types self.updater: Optional[Updater] = updater From 7de254138b591eb79b66e8aa9fb534731593ccec Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:34:14 +0200 Subject: [PATCH 4/5] try demonstrating again --- telegram/_message.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/telegram/_message.py b/telegram/_message.py index 3cd654abbd9..5b07060a323 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -1098,10 +1098,10 @@ def __init__( with self._unfrozen(): # Required - self.message_id: int = message_id + self.message_id = message_id # Optionals - self.from_user: Optional[User] = from_user - self.sender_chat: Optional[Chat] = sender_chat + self.from_user = from_user + self.sender_chat = sender_chat self.date: datetime.datetime = date self.chat: Chat = chat self.is_automatic_forward: Optional[bool] = is_automatic_forward From 4a44b95be6c7bbd6a732aef24785d40798f778da Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Wed, 10 Jul 2024 12:52:29 +0200 Subject: [PATCH 5/5] Revert "try demonstrating again" This reverts commit 7de254138b591eb79b66e8aa9fb534731593ccec. --- telegram/_message.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/telegram/_message.py b/telegram/_message.py index 5b07060a323..3cd654abbd9 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -1098,10 +1098,10 @@ def __init__( with self._unfrozen(): # Required - self.message_id = message_id + self.message_id: int = message_id # Optionals - self.from_user = from_user - self.sender_chat = sender_chat + self.from_user: Optional[User] = from_user + self.sender_chat: Optional[Chat] = sender_chat self.date: datetime.datetime = date self.chat: Chat = chat self.is_automatic_forward: Optional[bool] = is_automatic_forward