Skip to content

fix: change the Downloadable protocol to be non-writable to shut up type checking that checks code that uses the bot.download(...) method#1628

Merged
JrooTJunior merged 4 commits intoaiogram:dev-3.xfrom
monosans:patch-1
Jan 19, 2025
Merged

Conversation

@monosans
Copy link
Contributor

@monosans monosans commented Jan 9, 2025

The following code gives error with type-checkers, because TelegramObject is frozen and Downloadable Protocol expects file_id to be writable:

from aiogram import Bot
from aiogram.types import Document


async def main() -> None:
    async with Bot("") as bot:
        await bot.download(Document(file_id="", file_unique_id=""))
error: Argument 1 to "download" of "Bot" has incompatible type "Document"; expected "str | Downloadable"  [arg-type]
note: Protocol member Downloadable.file_id expected settable variable, got read-only attribute

Type of change

  • Bug fix (non-breaking change which fixes an issue)

@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label Jan 9, 2025
@github-actions
Copy link

github-actions bot commented Jan 9, 2025

✔️ Changelog found.

Thank you for adding a description of the changes

@codecov
Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (bbdc43b) to head (73f0ff9).
Report is 1 commits behind head on dev-3.x.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x     #1628   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          484       484           
  Lines        12205     12206    +1     
=========================================
+ Hits         12205     12206    +1     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
aiogram/types/downloadable.py 100.00% <100.00%> (ø)

@Olegt0rr Olegt0rr added the typing Issues related to the type hints and static typing label Jan 12, 2025
Co-authored-by: Alex Root Junior <[email protected]>
@monosans monosans requested a review from JrooTJunior January 17, 2025 14:51
@monosans monosans changed the title fix: don't require Downloadable.file_id to be writable fix: change the Downloadable protocol to be non-writable to shut up type checking that checks code that uses the bot.download(...) method Jan 17, 2025
@JrooTJunior JrooTJunior merged commit 6e81294 into aiogram:dev-3.x Jan 19, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Issue or PR for stable 3.x version typing Issues related to the type hints and static typing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants