Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Parse enums from documentation #11

Open
evgfilim1 opened this issue Jul 2, 2022 · 0 comments
Open

Parse enums from documentation #11

evgfilim1 opened this issue Jul 2, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@evgfilim1
Copy link
Contributor

evgfilim1 commented Jul 2, 2022

Example

We have type attribute in Chat class
image

So we should create an enum like this:

from aiogram.utils.enum import AutoName

from enum import auto


class ChatType(AutoName):
    PRIVATE = auto()
    GROUP = auto()
    SUPERGROUP = auto()
    CHANNEL = auto()

Enum class name should be generated from base class name and target field name capitalized: Chat + Type.
For MessageEntity.type field it should be MessageEntityType, so following the same rules.

More complex example

We have ChatMember and its subclasses that differ in status attribute
image

So we should create an enum like this:

from aiogram.utils.enum import AutoName

from enum import auto


class ChatMemberStatus(AutoName):
    CREATOR = auto()
    ADMINISTRATOR = auto()
    MEMBER = auto()
    RESTRICTED = auto()
    LEFT = auto()
    KICKED = auto()

Enum class name should be generated in the same way: ChatMember + Status.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant