typingsfix

This commit is contained in:
tonyrewin 2022-07-21 19:11:39 +03:00
parent 2ff715eb50
commit 817002b17b
7 changed files with 18 additions and 17 deletions

View File

@ -38,7 +38,7 @@ class Reaction(Base):
oid: str = Column(String, nullable=True, comment="Old ID") oid: str = Column(String, nullable=True, comment="Old ID")
@property @property
async def stat(self) -> dict: async def stat(self) -> Dict:
reacted = 0 reacted = 0
try: try:
with local_session() as session: with local_session() as session:

View File

@ -61,7 +61,7 @@ class Shout(Base):
oid: str = Column(String, nullable=True) oid: str = Column(String, nullable=True)
@property @property
async def stat(self) -> dict: async def stat(self) -> Dict:
return { return {
"viewed": await ViewedStorage.get_shout(self.slug), "viewed": await ViewedStorage.get_shout(self.slug),
"reacted": await ReactionsStorage.by_shout(self.slug) "reacted": await ReactionsStorage.by_shout(self.slug)

View File

@ -4,7 +4,7 @@ from orm.user import User
from resolvers.base import mutation, query from resolvers.base import mutation, query
from auth.authenticate import login_required from auth.authenticate import login_required
from datetime import datetime from datetime import datetime
from typing import List
from sqlalchemy import and_ from sqlalchemy import and_
@mutation.field("createCommunity") @mutation.field("createCommunity")
@ -92,7 +92,7 @@ def community_unfollow(user, slug):
session.commit() session.commit()
@query.field("userFollowedCommunities") @query.field("userFollowedCommunities")
def get_followed_communities(_, user_slug) -> list[Community]: def get_followed_communities(_, user_slug) -> List[Community]:
ccc = [] ccc = []
with local_session() as session: with local_session() as session:
ccc = session.query(Community.slug).\ ccc = session.query(Community.slug).\

View File

@ -5,10 +5,11 @@ from orm.reaction import Reaction
from orm.shout import Shout, ShoutAuthor, ShoutTopic from orm.shout import Shout, ShoutAuthor, ShoutTopic
from orm.topic import TopicFollower from orm.topic import TopicFollower
from orm.user import AuthorFollower from orm.user import AuthorFollower
from typing import List
@query.field("shoutsForFeed") @query.field("shoutsForFeed")
@login_required @login_required
def get_user_feed(_, info, page, size) -> list[Shout]: def get_user_feed(_, info, page, size) -> List[Shout]:
user = info.context["request"].user user = info.context["request"].user
shouts = [] shouts = []
with local_session() as session: with local_session() as session:
@ -27,7 +28,7 @@ def get_user_feed(_, info, page, size) -> list[Shout]:
@query.field("myCandidates") @query.field("myCandidates")
@login_required @login_required
async def user_unpublished_shouts(_, info, page = 1, size = 10) -> list[Shout]: async def user_unpublished_shouts(_, info, page = 1, size = 10) -> List[Shout]:
user = info.context["request"].user user = info.context["request"].user
shouts = [] shouts = []
with local_session() as session: with local_session() as session:

View File

@ -11,10 +11,10 @@ from auth.authenticate import login_required
from inbox_resolvers.inbox import get_inbox_counter from inbox_resolvers.inbox import get_inbox_counter
from sqlalchemy import and_, desc from sqlalchemy import and_, desc
from sqlalchemy.orm import selectinload from sqlalchemy.orm import selectinload
from typing import List
@query.field("userReactedShouts") @query.field("userReactedShouts")
async def get_user_reacted_shouts(_, info, slug, page, size) -> list[Shout]: async def get_user_reacted_shouts(_, info, slug, page, size) -> List[Shout]:
user = await UserStorage.get_user_by_slug(slug) user = await UserStorage.get_user_by_slug(slug)
if not user: return {} if not user: return {}
with local_session() as session: with local_session() as session:
@ -29,7 +29,7 @@ async def get_user_reacted_shouts(_, info, slug, page, size) -> list[Shout]:
@query.field("userFollowedTopics") @query.field("userFollowedTopics")
@login_required @login_required
def get_followed_topics(_, slug) -> list[Topic]: def get_followed_topics(_, slug) -> List[Topic]:
rows = [] rows = []
with local_session() as session: with local_session() as session:
rows = session.query(Topic).\ rows = session.query(Topic).\
@ -40,7 +40,7 @@ def get_followed_topics(_, slug) -> list[Topic]:
@query.field("userFollowedAuthors") @query.field("userFollowedAuthors")
def get_followed_authors(_, slug) -> list[User]: def get_followed_authors(_, slug) -> List[User]:
authors = [] authors = []
with local_session() as session: with local_session() as session:
authors = session.query(User).\ authors = session.query(User).\
@ -51,7 +51,7 @@ def get_followed_authors(_, slug) -> list[User]:
@query.field("userFollowers") @query.field("userFollowers")
async def user_followers(_, slug) -> list[User]: async def user_followers(_, slug) -> List[User]:
with local_session() as session: with local_session() as session:
users = session.query(User).\ users = session.query(User).\
join(AuthorFollower, User.slug == AuthorFollower.follower).\ join(AuthorFollower, User.slug == AuthorFollower.follower).\

View File

@ -9,7 +9,7 @@ from auth.authenticate import login_required
from datetime import datetime from datetime import datetime
from storages.reactions import ReactionsStorage from storages.reactions import ReactionsStorage
from storages.viewed import ViewedStorage from storages.viewed import ViewedStorage
from typing import List
def reactions_follow(user, slug, auto=False): def reactions_follow(user, slug, auto=False):
with local_session() as session: with local_session() as session:
@ -104,7 +104,7 @@ async def delete_reaction(_, info, id):
return {} return {}
@query.field("reactionsByShout") @query.field("reactionsByShout")
def get_shout_reactions(_, info, slug) -> list[Shout]: def get_shout_reactions(_, info, slug) -> List[Shout]:
shouts = [] shouts = []
with local_session() as session: with local_session() as session:
shoutslugs = session.query(ShoutReactionsFollower.shout).\ shoutslugs = session.query(ShoutReactionsFollower.shout).\
@ -117,7 +117,7 @@ def get_shout_reactions(_, info, slug) -> list[Shout]:
@query.field("reactionsAll") @query.field("reactionsAll")
def get_all_reactions(_, info, page=1, size=10) -> list[Reaction]: def get_all_reactions(_, info, page=1, size=10) -> List[Reaction]:
reactions = [] reactions = []
with local_session() as session: with local_session() as session:
q = session.query(Reaction).\ q = session.query(Reaction).\
@ -134,7 +134,7 @@ def get_all_reactions(_, info, page=1, size=10) -> list[Reaction]:
@query.field("reactionsByAuthor") @query.field("reactionsByAuthor")
def get_reactions_by_author(_, info, slug, page=1, size=50) -> list[Reaction]: def get_reactions_by_author(_, info, slug, page=1, size=50) -> List[Reaction]:
reactions = [] reactions = []
with local_session() as session: with local_session() as session:
reactions = session.query(Reaction).\ reactions = session.query(Reaction).\

View File

@ -4,7 +4,7 @@ import asyncio
from orm.base import local_session from orm.base import local_session
from storages.shoutauthor import ShoutAuthorStorage from storages.shoutauthor import ShoutAuthorStorage
from orm.topic import ShoutTopic, TopicFollower from orm.topic import ShoutTopic, TopicFollower
from typing import Dict
class TopicStat: class TopicStat:
shouts_by_topic = {} shouts_by_topic = {}
@ -55,7 +55,7 @@ class TopicStat:
return self.shouts_by_topic.get(topic, []) return self.shouts_by_topic.get(topic, [])
@staticmethod @staticmethod
async def get_stat(topic) -> dict: async def get_stat(topic) -> Dict:
self = TopicStat self = TopicStat
async with self.lock: async with self.lock:
shouts = self.shouts_by_topic.get(topic, []) shouts = self.shouts_by_topic.get(topic, [])