From 202c04e32b58fea908c2c6503309db0ba4cf3987 Mon Sep 17 00:00:00 2001 From: Mujy Date: Tue, 20 Jul 2021 10:27:04 -0400 Subject: [PATCH] Improved typing --- Weverse/models/__init__.py | 2 +- Weverse/models/artist.py | 8 +++++++- Weverse/models/comment.py | 7 ++++++- Weverse/models/community.py | 10 ++++++++-- Weverse/models/photo.py | 8 +++++++- Weverse/models/video.py | 8 +++++++- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Weverse/models/__init__.py b/Weverse/models/__init__.py index 556e956..90fabb2 100644 --- a/Weverse/models/__init__.py +++ b/Weverse/models/__init__.py @@ -1,5 +1,5 @@ -from .artist import Artist from .comment import Comment +from .artist import Artist from .community import Community from .notification import Notification from .photo import Photo diff --git a/Weverse/models/artist.py b/Weverse/models/artist.py index 4de9e01..a728429 100644 --- a/Weverse/models/artist.py +++ b/Weverse/models/artist.py @@ -1,3 +1,9 @@ +from typing import Optional, TYPE_CHECKING + +if TYPE_CHECKING: + from Weverse.models import Community + + class Artist: r"""An Artist object that represents a Weverse Artist that belongs in a community. @@ -111,5 +117,5 @@ def __init__(self, **kwargs): self.to_fan_last_created_at = kwargs.get('to_fan_last_created_at') self.to_fan_last_expire_in = kwargs.get('to_fan_last_expire_in') self.birthday_img_url = kwargs.get('birthday_img_url') - self.community = None + self.community: Optional[Community] = None self.posts = [] diff --git a/Weverse/models/comment.py b/Weverse/models/comment.py index bddb6e6..7d53f1b 100644 --- a/Weverse/models/comment.py +++ b/Weverse/models/comment.py @@ -1,3 +1,8 @@ +from typing import Optional, TYPE_CHECKING + +if TYPE_CHECKING: + from Weverse.models import Post + class Comment: r"""A Comment object that represents a Weverse Comment that belongs to an Artist. @@ -60,4 +65,4 @@ def __init__(self, **kwargs): self.post_id = kwargs.get('post_id') self.created_at = kwargs.get('created_at') self.updated_at = kwargs.get('updated_at') - self.post = None + self.post: Optional[Post] = None diff --git a/Weverse/models/community.py b/Weverse/models/community.py index 008489b..d5936c7 100644 --- a/Weverse/models/community.py +++ b/Weverse/models/community.py @@ -1,3 +1,9 @@ +from typing import List, TYPE_CHECKING + +if TYPE_CHECKING: + from Weverse.models import Artist, Tab + + class Community: r"""A Comment object that represents a Weverse Comment that belongs to an Artist. @@ -67,6 +73,6 @@ def __init__(self, **kwargs): self.full_name = kwargs.get('full_name') self.fc_member = kwargs.get('fc_member') self.show_member_count = kwargs.get('show_member_count') - self.artists = [] - self.tabs = [] + self.artists: List[Artist] = [] + self.tabs: List[Tab] = [] diff --git a/Weverse/models/photo.py b/Weverse/models/photo.py index da6c64e..3d43f9e 100644 --- a/Weverse/models/photo.py +++ b/Weverse/models/photo.py @@ -1,3 +1,9 @@ +from typing import Optional, TYPE_CHECKING + +if TYPE_CHECKING: + from Weverse.models import Post + + class Photo: r"""A Photo object that represents a Weverse Photo that belongs to media or a post. @@ -63,5 +69,5 @@ def __init__(self, **kwargs): self.original_img_width = kwargs.get('original_img_width') self.original_img_height = kwargs.get('original_img_height') self.file_name = kwargs.get('file_name') - self.post = None + self.post: Optional[Post] = None diff --git a/Weverse/models/video.py b/Weverse/models/video.py index b870984..603d070 100644 --- a/Weverse/models/video.py +++ b/Weverse/models/video.py @@ -1,3 +1,9 @@ +from typing import Optional, TYPE_CHECKING + +if TYPE_CHECKING: + from Weverse.models import Post + + class Video: r"""A Video object that represents a Weverse Video that belongs to media or a post. @@ -42,5 +48,5 @@ def __init__(self, **kwargs): self.thumbnail_width = kwargs.get('thumbnail_width') self.thumbnail_height = kwargs.get('thumbnail_height') self.length = kwargs.get('length') - self.post = None + self.post: Optional[Post] = None