Skip to content

Add class helper ChatAction #803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 9, 2022
Merged

Conversation

ShiroNoHaga
Copy link
Contributor

@ShiroNoHaga ShiroNoHaga commented Jan 3, 2022

Description

Add class helper ChatAction for constants that Telegram BotAPI uses in send_chat_action request.
In my opinion, this will help users and will also improve compatibility with 2.x version.

Difference from 2.x version:
• No class methods;
• Renamed ChatActions to ChatAction;
• Better class description.

Type of change

Please delete options that are not relevant.

  • Documentation (typos, code examples or any documentation update)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Testing code:

from aiogram.types.chat_action import ChatAction
from aiogram import types
import aiogram

assert types.ChatAction == ChatAction
assert aiogram.types.ChatAction == ChatAction
assert aiogram.types.ChatAction.TYPING == ChatAction.TYPING
assert ChatAction.TYPING == "typing"

print("Tests passed.")

Test Configuration:

  • Python version: 3.8

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@evgfilim1 evgfilim1 added 3.x Issue or PR for stable 3.x version new feature Missing feature under discussion A subject of discussion labels Jan 3, 2022
@ShiroNoHaga
Copy link
Contributor Author

ShiroNoHaga commented Jan 4, 2022

Updated. Change using helper to using enum.Enum.

Small test code:

from aiogram.types.chat_action import ChatAction
from aiogram import types
import aiogram


async def main():
    assert types.ChatAction == ChatAction
    assert aiogram.types.ChatAction == ChatAction
    assert aiogram.types.ChatAction.TYPING == ChatAction.TYPING
    assert ChatAction.TYPING == "typing"
    print("Import tests passed.")

    from aiogram import Bot
    BOT_TOKEN = ""  # bot token here
    CHAT_ID = 0     # user id to send action

    bot = Bot(BOT_TOKEN)
    await bot.send_chat_action(chat_id=CHAT_ID, action=ChatAction.TYPING)
    await bot.send_chat_action(chat_id=CHAT_ID, action="typing")
    await bot.session.close()
    print("Implementation tests passed.")


if __name__ == '__main__':
    import asyncio
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

@evgfilim1
Copy link
Contributor

Small test code

@ShiroNoHaga, please add tests to tests/ directory.

@ShiroNoHaga
Copy link
Contributor Author

@evgfilim1 , added tests.

@ShiroNoHaga

This comment has been minimized.

@codecov
Copy link

codecov bot commented Jan 4, 2022

Codecov Report

Merging #803 (ba61bcd) into dev-3.x (416460e) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x      #803   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          301       303    +2     
  Lines         8150      8171   +21     
=========================================
+ Hits          8150      8171   +21     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

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

Impacted Files Coverage Δ
aiogram/types/__init__.py 100.00% <100.00%> (ø)
aiogram/types/chat_action.py 100.00% <100.00%> (ø)
aiogram/utils/enum.py 100.00% <100.00%> (ø)

Copy link
Contributor

@evgfilim1 evgfilim1 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@evgfilim1 evgfilim1 requested a review from JrooTJunior January 4, 2022 19:00
@evgfilim1 evgfilim1 removed the under discussion A subject of discussion label Jan 5, 2022
@ShiroNoHaga

This comment has been minimized.

Copy link
Contributor

@evgfilim1 evgfilim1 left a comment

Choose a reason for hiding this comment

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

Good

Copy link

@okineadev okineadev left a comment

Choose a reason for hiding this comment

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

norm

@github-actions
Copy link

✔️ Changelog found.

Thank you for adding a description of the changes

@Olegt0rr
Copy link
Contributor

@evgfilim1, don't forget to add it to 2x->3x migration guide

@evgfilim1

This comment was marked as resolved.

@Olegt0rr
Copy link
Contributor

Olegt0rr commented Jul 3, 2022

enum.auto() is not typehinted, so MyPy can't recognise auto()'s result as str

@evgfilim1

This comment was marked as off-topic.

@JrooTJunior JrooTJunior merged commit 851f7a2 into aiogram:dev-3.x Jul 9, 2022
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 new feature Missing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants