fix: add support of type hints for factories

This commit is contained in:
Egor 2020-07-03 16:29:04 +05:00
parent 6e93facffc
commit 8f3913b728
4 changed files with 28 additions and 0 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)