From ee78cd77605c58f2111572f9e13e3e658ca7272a Mon Sep 17 00:00:00 2001 From: Deimos Date: Wed, 7 Oct 2020 16:19:28 -0600 Subject: [PATCH] Update Black to version 20.8b1 Updates the Black code-formatter for Python to the latest version, and applies it to some files that had formatting that the new version does differently (splitting collections with trailing commas across lines). --- tildes/requirements-dev.txt | 2 +- tildes/tildes/enums.py | 3 +- .../models/comment/comment_notification.py | 12 ++++--- tildes/tildes/models/group/group_stat.py | 5 ++- tildes/tildes/models/topic/topic.py | 12 +++++-- tildes/tildes/schemas/fields.py | 36 +++++++++++++++---- tildes/tildes/views/ignored_topics.py | 5 ++- 7 files changed, 58 insertions(+), 17 deletions(-) diff --git a/tildes/requirements-dev.txt b/tildes/requirements-dev.txt index 5713da4..7903c5d 100644 --- a/tildes/requirements-dev.txt +++ b/tildes/requirements-dev.txt @@ -6,7 +6,7 @@ astroid==2.4.1 # via prospector, pylint, pylint-celery, pylint-flask, attrs==20.2.0 # via pytest backcall==0.2.0 # via ipython beautifulsoup4==4.9.3 -black==19.10b0 +black==20.8b1 bleach==3.2.1 cached-property==1.5.2 # via pygit2 certifi==2020.6.20 # via requests, sentry-sdk diff --git a/tildes/tildes/enums.py b/tildes/tildes/enums.py index 756d930..a17945a 100644 --- a/tildes/tildes/enums.py +++ b/tildes/tildes/enums.py @@ -107,7 +107,8 @@ class ContentMetadataFields(enum.Enum): @classmethod def detail_fields_for_content_type( - cls, content_type: "TopicContentType", + cls, + content_type: "TopicContentType", ) -> List["ContentMetadataFields"]: """Return a list of fields to display for detail about a particular type.""" if content_type is TopicContentType.ARTICLE: diff --git a/tildes/tildes/models/comment/comment_notification.py b/tildes/tildes/models/comment/comment_notification.py index 4b83026..4bc6a86 100644 --- a/tildes/tildes/models/comment/comment_notification.py +++ b/tildes/tildes/models/comment/comment_notification.py @@ -57,10 +57,14 @@ class CommentNotification(DatabaseModel): self, user: User, comment: Comment, notification_type: CommentNotificationType ): """Create a new notification for a user from a comment.""" - if notification_type in ( - CommentNotificationType.COMMENT_REPLY, - CommentNotificationType.TOPIC_REPLY, - ) and not self.should_create_reply_notification(comment): + if ( + notification_type + in ( + CommentNotificationType.COMMENT_REPLY, + CommentNotificationType.TOPIC_REPLY, + ) + and not self.should_create_reply_notification(comment) + ): raise ValueError("That comment shouldn't create a reply notification") self.user = user diff --git a/tildes/tildes/models/group/group_stat.py b/tildes/tildes/models/group/group_stat.py index c0f61fa..507c66d 100644 --- a/tildes/tildes/models/group/group_stat.py +++ b/tildes/tildes/models/group/group_stat.py @@ -23,7 +23,10 @@ class GroupStat(DatabaseModel): __tablename__ = "group_stats" group_id: int = Column( - Integer, ForeignKey("groups.group_id"), nullable=False, primary_key=True, + Integer, + ForeignKey("groups.group_id"), + nullable=False, + primary_key=True, ) stat: GroupStatType = Column(ENUM(GroupStatType), nullable=False, primary_key=True) period: DateTimeTZRange = Column(TSTZRANGE, nullable=False, primary_key=True) diff --git a/tildes/tildes/models/topic/topic.py b/tildes/tildes/models/topic/topic.py index a848c29..3e16c00 100644 --- a/tildes/tildes/models/topic/topic.py +++ b/tildes/tildes/models/topic/topic.py @@ -87,14 +87,20 @@ class Topic(DatabaseModel): Integer, ForeignKey("topic_schedule.schedule_id"), index=True ) created_time: datetime = Column( - TIMESTAMP(timezone=True), nullable=False, server_default=text("NOW()"), + TIMESTAMP(timezone=True), + nullable=False, + server_default=text("NOW()"), ) last_edited_time: Optional[datetime] = Column(TIMESTAMP(timezone=True)) last_activity_time: datetime = Column( - TIMESTAMP(timezone=True), nullable=False, server_default=text("NOW()"), + TIMESTAMP(timezone=True), + nullable=False, + server_default=text("NOW()"), ) last_interesting_activity_time: datetime = Column( - TIMESTAMP(timezone=True), nullable=False, server_default=text("NOW()"), + TIMESTAMP(timezone=True), + nullable=False, + server_default=text("NOW()"), ) is_deleted: bool = Column( Boolean, nullable=False, server_default="false", index=True diff --git a/tildes/tildes/schemas/fields.py b/tildes/tildes/schemas/fields.py index 2d54e7b..684b81f 100644 --- a/tildes/tildes/schemas/fields.py +++ b/tildes/tildes/schemas/fields.py @@ -37,7 +37,11 @@ class Enum(Field): return value.name.lower() def _deserialize( - self, value: str, attr: Optional[str], data: DataType, **kwargs: Any, + self, + value: str, + attr: Optional[str], + data: DataType, + **kwargs: Any, ) -> enum.Enum: """Deserialize a string to the enum member with that name.""" if not self._enum_class: @@ -64,7 +68,11 @@ class ShortTimePeriod(Field): """ def _deserialize( - self, value: str, attr: Optional[str], data: DataType, **kwargs: Any, + self, + value: str, + attr: Optional[str], + data: DataType, + **kwargs: Any, ) -> Optional[SimpleHoursPeriod]: """Deserialize to a SimpleHoursPeriod object.""" if value == "all": @@ -76,7 +84,11 @@ class ShortTimePeriod(Field): raise ValidationError("Invalid time period") def _serialize( - self, value: Optional[SimpleHoursPeriod], attr: str, obj: object, **kwargs: Any, + self, + value: Optional[SimpleHoursPeriod], + attr: str, + obj: object, + **kwargs: Any, ) -> Optional[str]: """Serialize the value to the "short form" string.""" if not value: @@ -105,7 +117,11 @@ class Markdown(Field): raise ValidationError("Cannot be entirely whitespace.") def _deserialize( - self, value: str, attr: Optional[str], data: DataType, **kwargs: Any, + self, + value: str, + attr: Optional[str], + data: DataType, + **kwargs: Any, ) -> str: """Deserialize the string, removing carriage returns in the process.""" value = value.replace("\r", "") @@ -138,7 +154,11 @@ class SimpleString(Field): super().__init__(validate=Length(min=1, max=max_length), **kwargs) def _deserialize( - self, value: str, attr: Optional[str], data: DataType, **kwargs: Any, + self, + value: str, + attr: Optional[str], + data: DataType, + **kwargs: Any, ) -> str: """Deserialize the string, removing/replacing as necessary.""" return simplify_string(value) @@ -162,7 +182,11 @@ class Ltree(Field): return value.path def _deserialize( - self, value: str, attr: Optional[str], data: DataType, **kwargs: Any, + self, + value: str, + attr: Optional[str], + data: DataType, + **kwargs: Any, ) -> sqlalchemy_utils.Ltree: """Deserialize a string path to an Ltree object.""" # convert to lowercase and replace spaces with underscores diff --git a/tildes/tildes/views/ignored_topics.py b/tildes/tildes/views/ignored_topics.py index d79025f..e434e22 100644 --- a/tildes/tildes/views/ignored_topics.py +++ b/tildes/tildes/views/ignored_topics.py @@ -14,7 +14,10 @@ from tildes.views.decorators import use_kwargs @view_config(route_name="ignored_topics", renderer="ignored_topics.jinja2") @use_kwargs(PaginatedListingSchema()) def get_ignored_topics( - request: Request, after: Optional[str], before: Optional[str], per_page: int, + request: Request, + after: Optional[str], + before: Optional[str], + per_page: int, ) -> dict: """Generate the ignored topics page.""" # pylint: disable=unused-argument