mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
fix: add support of type hints for factories
This commit is contained in:
parent
6e93facffc
commit
8f3913b728
4 changed files with 28 additions and 0 deletions
|
|
@ -26,3 +26,10 @@ class ChatFactory(factory.Factory):
|
|||
def title(self, n):
|
||||
if self.type is ChatType.CHANNEL:
|
||||
return f"Title #{n}"
|
||||
|
||||
def __new__(cls, *args, **kwargs) -> "ChatFactory.Meta.model":
|
||||
"""
|
||||
This is a dirty hack for correct type hints
|
||||
See https://github.com/FactoryBoy/factory_boy/issues/468#issuecomment-505646794
|
||||
"""
|
||||
return super().__new__(*args, **kwargs)
|
||||
|
|
@ -11,3 +11,10 @@ class ChatMemberFactory(factory.Factory):
|
|||
user = factory.SubFactory(UserFactory)
|
||||
|
||||
status = ChatMemberStatus.ADMINISTRATOR
|
||||
|
||||
def __new__(cls, *args, **kwargs) -> "ChatMemberFactory.Meta.model":
|
||||
"""
|
||||
This is a dirty hack for correct type hints
|
||||
See https://github.com/FactoryBoy/factory_boy/issues/468#issuecomment-505646794
|
||||
"""
|
||||
return super().__new__(*args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -18,3 +18,10 @@ class MessageFactory(factory.Factory):
|
|||
text = factory.Sequence(lambda n: f"Message text #{n}")
|
||||
|
||||
date = factory.LazyFunction(lambda _: datetime.now().toordinal())
|
||||
|
||||
def __new__(cls, *args, **kwargs) -> "MessageFactory.Meta.model":
|
||||
"""
|
||||
This is a dirty hack for correct type hints
|
||||
See https://github.com/FactoryBoy/factory_boy/issues/468#issuecomment-505646794
|
||||
"""
|
||||
return super().__new__(*args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -11,3 +11,10 @@ class UserFactory(factory.Factory):
|
|||
id = sequences.id_
|
||||
first_name = factory.Sequence(lambda n: f"First name #{n}")
|
||||
is_bot = False
|
||||
|
||||
def __new__(cls, *args, **kwargs) -> "UserFactory.Meta.model":
|
||||
"""
|
||||
This is a dirty hack for correct type hints
|
||||
See https://github.com/FactoryBoy/factory_boy/issues/468#issuecomment-505646794
|
||||
"""
|
||||
return super().__new__(*args, **kwargs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue