From a9bb4a7122df6d9d4a764de52244c6ec75789ead Mon Sep 17 00:00:00 2001 From: Paolo Melchiorre Date: Mon, 5 Dec 2022 18:38:37 +0100 Subject: Add pyupgrade with --py310-plus in pre-commit (#103) --- activities/models/hashtag.py | 7 +++---- activities/models/post.py | 15 ++++++++------- activities/models/post_interaction.py | 6 ++---- activities/views/search.py | 6 ++---- 4 files changed, 15 insertions(+), 19 deletions(-) (limited to 'activities') diff --git a/activities/models/hashtag.py b/activities/models/hashtag.py index b7f0832..162f8b4 100644 --- a/activities/models/hashtag.py +++ b/activities/models/hashtag.py @@ -1,6 +1,5 @@ import re from datetime import date, timedelta -from typing import Dict, List import urlman from asgiref.sync import sync_to_async @@ -138,7 +137,7 @@ class Hashtag(StatorModel): def __str__(self): return self.display_name - def usage_months(self, num: int = 12) -> Dict[date, int]: + def usage_months(self, num: int = 12) -> dict[date, int]: """ Return the most recent num months of stats """ @@ -153,7 +152,7 @@ class Hashtag(StatorModel): results[date(year, month, 1)] = val return dict(sorted(results.items(), reverse=True)[:num]) - def usage_days(self, num: int = 7) -> Dict[date, int]: + def usage_days(self, num: int = 7) -> dict[date, int]: """ Return the most recent num days of stats """ @@ -170,7 +169,7 @@ class Hashtag(StatorModel): return dict(sorted(results.items(), reverse=True)[:num]) @classmethod - def hashtags_from_content(cls, content) -> List[str]: + def hashtags_from_content(cls, content) -> list[str]: """ Return a parsed and sanitized of hashtags found in content without leading '#'. diff --git a/activities/models/post.py b/activities/models/post.py index ee1f393..5ca5a1b 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -1,5 +1,6 @@ import re -from typing import Dict, Iterable, List, Optional, Set +from collections.abc import Iterable +from typing import Optional import httpx import urlman @@ -324,10 +325,10 @@ class Post(StatorModel): cls, author: Identity, content: str, - summary: Optional[str] = None, + summary: str | None = None, visibility: int = Visibilities.public, reply_to: Optional["Post"] = None, - attachments: Optional[List] = None, + attachments: list | None = None, ) -> "Post": with transaction.atomic(): # Find mentions in this post @@ -363,9 +364,9 @@ class Post(StatorModel): def edit_local( self, content: str, - summary: Optional[str] = None, + summary: str | None = None, visibility: int = Visibilities.public, - attachments: Optional[List] = None, + attachments: list | None = None, ): with transaction.atomic(): # Strip all HTML and apply linebreaks filter @@ -380,7 +381,7 @@ class Post(StatorModel): self.save() @classmethod - def mentions_from_content(cls, content, author) -> Set[Identity]: + def mentions_from_content(cls, content, author) -> set[Identity]: mention_hits = cls.mention_regex.findall(content) mentions = set() for precursor, handle in mention_hits: @@ -413,7 +414,7 @@ class Post(StatorModel): ### ActivityPub (outbound) ### - def to_ap(self) -> Dict: + def to_ap(self) -> dict: """ Returns the AP JSON for this object """ diff --git a/activities/models/post_interaction.py b/activities/models/post_interaction.py index a913a0f..0bc2fff 100644 --- a/activities/models/post_interaction.py +++ b/activities/models/post_interaction.py @@ -1,5 +1,3 @@ -from typing import Dict - from django.db import models, transaction from django.utils import timezone @@ -195,7 +193,7 @@ class PostInteraction(StatorModel): ### ActivityPub (outbound) ### - def to_ap(self) -> Dict: + def to_ap(self) -> dict: """ Returns the AP JSON for this object """ @@ -223,7 +221,7 @@ class PostInteraction(StatorModel): raise ValueError("Cannot turn into AP") return value - def to_undo_ap(self) -> Dict: + def to_undo_ap(self) -> dict: """ Returns the AP JSON to undo this object """ diff --git a/activities/views/search.py b/activities/views/search.py index ccfc1a4..f7ab237 100644 --- a/activities/views/search.py +++ b/activities/views/search.py @@ -1,5 +1,3 @@ -from typing import Set - import httpx from asgiref.sync import async_to_sync from django import forms @@ -32,7 +30,7 @@ class Search(FormView): # Try to fetch the user by handle query = query.lstrip("@") - results: Set[Identity] = set() + results: set[Identity] = set() if "@" in query: username, domain = query.split("@", 1) @@ -118,7 +116,7 @@ class Search(FormView): if "@" in query or "://" in query: return set() - results: Set[Hashtag] = set() + results: set[Hashtag] = set() query = query.lstrip("#") for hashtag in Hashtag.objects.public().hashtag_or_alias(query)[:10]: results.add(hashtag) -- cgit v1.2.3