diff --git a/tildes/requirements.txt b/tildes/requirements.txt index d396c45..b500f83 100644 --- a/tildes/requirements.txt +++ b/tildes/requirements.txt @@ -34,7 +34,7 @@ MarkupSafe==1.1.1 marshmallow==2.19.5 mccabe==0.6.1 more-itertools==7.1.0 -mypy==0.711 +mypy==0.720 mypy-extensions==0.4.1 packaging==19.0 parso==0.5.1 @@ -101,6 +101,7 @@ traitlets==4.3.2 transaction==2.4.0 translationstring==1.3 typed-ast==1.4.0 +typing-extensions==3.7.4 urllib3==1.25.3 venusian==1.2.0 waitress==1.3.0 diff --git a/tildes/tildes/models/comment/comment.py b/tildes/tildes/models/comment/comment.py index 0044404..38c190d 100644 --- a/tildes/tildes/models/comment/comment.py +++ b/tildes/tildes/models/comment/comment.py @@ -5,11 +5,10 @@ from collections import Counter from datetime import datetime, timedelta -from typing import Any, Optional, Sequence, Tuple +from typing import Any, Optional, Sequence, Tuple, TYPE_CHECKING from pyramid.security import Allow, Authenticated, Deny, DENY_ALL, Everyone from sqlalchemy import Boolean, Column, ForeignKey, Integer, Text, TIMESTAMP -from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import deferred, relationship from sqlalchemy.sql.expression import text @@ -23,6 +22,10 @@ from tildes.models.topic import Topic from tildes.models.user import User from tildes.schemas.comment import CommentSchema +if TYPE_CHECKING: # workaround for mypy issues with @hybrid_property + from builtins import property as hybrid_property +else: + from sqlalchemy.ext.hybrid import hybrid_property # edits inside this period after creation will not mark the comment as edited EDIT_GRACE_PERIOD = timedelta(minutes=5) @@ -96,7 +99,7 @@ class Comment(DatabaseModel): """Return the comment's markdown.""" return self._markdown - @markdown.setter # type: ignore + @markdown.setter def markdown(self, new_markdown: str) -> None: """Set the comment's markdown and render its HTML.""" if new_markdown == self.markdown: diff --git a/tildes/tildes/models/topic/topic.py b/tildes/tildes/models/topic/topic.py index 1f8119a..a030d70 100644 --- a/tildes/tildes/models/topic/topic.py +++ b/tildes/tildes/models/topic/topic.py @@ -4,7 +4,7 @@ """Contains the Topic class.""" from datetime import datetime, timedelta -from typing import Any, Dict, List, Optional, Sequence, Tuple +from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING from pyramid.security import Allow, Authenticated, Deny, DENY_ALL, Everyone from sqlalchemy import ( @@ -18,7 +18,6 @@ from sqlalchemy import ( TIMESTAMP, ) from sqlalchemy.dialects.postgresql import ENUM, JSONB, TSVECTOR -from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.ext.mutable import MutableDict from sqlalchemy.orm import deferred, relationship from sqlalchemy.sql.expression import text @@ -38,6 +37,10 @@ from tildes.models.group import Group from tildes.models.user import User from tildes.schemas.topic import TITLE_MAX_LENGTH, TopicSchema +if TYPE_CHECKING: # workaround for mypy issues with @hybrid_property + from builtins import property as hybrid_property +else: + from sqlalchemy.ext.hybrid import hybrid_property # edits inside this period after creation will not mark the topic as edited EDIT_GRACE_PERIOD = timedelta(minutes=5) @@ -143,7 +146,7 @@ class Topic(DatabaseModel): return self._markdown - @markdown.setter # type: ignore + @markdown.setter def markdown(self, new_markdown: str) -> None: """Set the topic's markdown and render its HTML.""" if not self.is_text_type: @@ -171,7 +174,7 @@ class Topic(DatabaseModel): return sorted_tags - @tags.setter # type: ignore + @tags.setter def tags(self, new_tags: List[str]) -> None: self._tags = new_tags diff --git a/tildes/tildes/models/user/user.py b/tildes/tildes/models/user/user.py index d30679d..d705595 100644 --- a/tildes/tildes/models/user/user.py +++ b/tildes/tildes/models/user/user.py @@ -172,7 +172,7 @@ class User(DatabaseModel): def __init__(self, username: str, password: str): """Create a new user account.""" self.username = username - self.password = password + self.password = password # type: ignore def __acl__(self) -> Sequence[Tuple[str, Any, str]]: """Pyramid security ACL."""