Browse Source

Remove obsolete __init__ return type annotations

mypy 0.640 has made it so that it's no longer necessary to annotate the
return type for __init__ methods, since it's always None. The only time
it's necessary now is if the method doesn't have any arguments, since
this shows that the method should still be type-checked.
merge-requests/48/head
Deimos 6 years ago
parent
commit
ccb2fb5aa9
  1. 2
      tildes/consumers/site_icon_downloader.py
  2. 4
      tildes/consumers/topic_embedly_extractor.py
  3. 2
      tildes/consumers/topic_metadata_generator.py
  4. 2
      tildes/scripts/clean_private_data.py
  5. 2
      tildes/tildes/api.py
  6. 2
      tildes/tildes/auth.py
  7. 2
      tildes/tildes/lib/amqp.py
  8. 2
      tildes/tildes/lib/datetime.py
  9. 2
      tildes/tildes/lib/markdown.py
  10. 4
      tildes/tildes/lib/ratelimit.py
  11. 2
      tildes/tildes/models/comment/comment.py
  12. 2
      tildes/tildes/models/comment/comment_label.py
  13. 2
      tildes/tildes/models/comment/comment_notification.py
  14. 2
      tildes/tildes/models/comment/comment_notification_query.py
  15. 2
      tildes/tildes/models/comment/comment_query.py
  16. 4
      tildes/tildes/models/comment/comment_tree.py
  17. 2
      tildes/tildes/models/comment/comment_vote.py
  18. 2
      tildes/tildes/models/group/group.py
  19. 2
      tildes/tildes/models/group/group_query.py
  20. 2
      tildes/tildes/models/group/group_subscription.py
  21. 6
      tildes/tildes/models/log/log.py
  22. 8
      tildes/tildes/models/message/message.py
  23. 2
      tildes/tildes/models/model_query.py
  24. 4
      tildes/tildes/models/pagination.py
  25. 2
      tildes/tildes/models/scraper/scraper_result.py
  26. 2
      tildes/tildes/models/topic/topic_query.py
  27. 2
      tildes/tildes/models/topic/topic_vote.py
  28. 2
      tildes/tildes/models/user/user.py
  29. 2
      tildes/tildes/models/user/user_invite_code.py
  30. 2
      tildes/tildes/routes.py
  31. 8
      tildes/tildes/schemas/fields.py
  32. 2
      tildes/tildes/scrapers/embedly_scraper.py

2
tildes/consumers/site_icon_downloader.py

@ -23,7 +23,7 @@ class SiteIconDownloader(PgsqlQueueConsumer):
ICON_FOLDER = "/var/lib/site-icons-spriter/site-icons"
def __init__(self, queue_name: str, routing_keys: Sequence[str]) -> None:
def __init__(self, queue_name: str, routing_keys: Sequence[str]):
"""Initialize the consumer, including the public suffix list."""
super().__init__(queue_name, routing_keys)

4
tildes/consumers/topic_embedly_extractor.py

@ -28,9 +28,7 @@ RESCRAPE_DELAY = timedelta(hours=24)
class TopicEmbedlyExtractor(PgsqlQueueConsumer):
"""Consumer that fetches data from Embedly's Extract API for link topics."""
def __init__(
self, api_key: str, queue_name: str, routing_keys: Sequence[str]
) -> None:
def __init__(self, api_key: str, queue_name: str, routing_keys: Sequence[str]):
"""Initialize the consumer, including creating a scraper instance."""
super().__init__(queue_name, routing_keys)

2
tildes/consumers/topic_metadata_generator.py

@ -19,7 +19,7 @@ from tildes.models.topic import Topic
class TopicMetadataGenerator(PgsqlQueueConsumer):
"""Consumer that generates content_metadata for topics."""
def __init__(self, queue_name: str, routing_keys: Sequence[str]) -> None:
def __init__(self, queue_name: str, routing_keys: Sequence[str]):
"""Initialize the consumer, including the public suffix list."""
super().__init__(queue_name, routing_keys)

2
tildes/scripts/clean_private_data.py

@ -39,7 +39,7 @@ def clean_all_data(config_path: str) -> None:
class DataCleaner:
"""Container class for all methods related to cleaning up old data."""
def __init__(self, db_session: Session, retention_period: timedelta) -> None:
def __init__(self, db_session: Session, retention_period: timedelta):
"""Create a new DataCleaner."""
self.db_session = db_session
self.retention_cutoff = datetime.now() - retention_period

2
tildes/tildes/api.py

@ -15,7 +15,7 @@ class APIv0(Service):
name_prefix = "apiv0_"
base_path = "/api/v0"
def __init__(self, name: str, path: str, **kwargs: Any) -> None:
def __init__(self, name: str, path: str, **kwargs: Any):
"""Create a new service."""
name = self.name_prefix + name
path = self.base_path + path

2
tildes/tildes/auth.py

@ -26,7 +26,7 @@ class DefaultRootFactory:
__acl__ = ((Allow, Everyone, "view"),)
def __init__(self, request: Request) -> None:
def __init__(self, request: Request):
"""Root factory constructor - must take a request argument."""
pass

2
tildes/tildes/lib/amqp.py

@ -30,7 +30,7 @@ class PgsqlQueueConsumer(AbstractConsumer):
def __init__(
self, queue_name: str, routing_keys: Sequence[str], uses_db: bool = True
) -> None:
):
"""Initialize a new queue, bindings, and consumer for it."""
self.connection = Connection()
self.channel = self.connection.channel()

2
tildes/tildes/lib/datetime.py

@ -15,7 +15,7 @@ class SimpleHoursPeriod:
_SHORT_FORM_REGEX = re.compile(r"\d+[hd]", re.IGNORECASE)
def __init__(self, hours: int) -> None:
def __init__(self, hours: int):
"""Initialize a SimpleHoursPeriod from a number of hours."""
if hours <= 0:
raise ValueError("Period must be at least 1 hour.")

2
tildes/tildes/lib/markdown.py

@ -298,7 +298,7 @@ class LinkifyFilter(Filter):
def __init__(
self, source: NonRecursiveTreeWalker, skip_tags: Optional[List[str]] = None
) -> None:
):
"""Initialize a linkification filter to apply to HTML.
The skip_tags argument can be a list of tag names, and the contents of any of

4
tildes/tildes/lib/ratelimit.py

@ -33,7 +33,7 @@ class RateLimitResult:
remaining_limit: int,
time_until_max: timedelta,
time_until_retry: Optional[timedelta] = None,
) -> None:
):
"""Initialize a RateLimitResult."""
# pylint: disable=too-many-arguments
if is_allowed and time_until_retry is not None:
@ -171,7 +171,7 @@ class RateLimitedAction:
by_user: bool = True,
by_ip: bool = True,
redis: Optional[StrictRedis] = None,
) -> None:
):
"""Initialize the limits on a particular action.
The action will be limited to a maximum of `limit` calls over the time period

2
tildes/tildes/models/comment/comment.py

@ -125,7 +125,7 @@ class Comment(DatabaseModel):
author: User,
markdown: str,
parent_comment: Optional["Comment"] = None,
) -> None:
):
"""Create a new comment."""
self.topic = topic
self.user_id = author.user_id

2
tildes/tildes/models/comment/comment_label.py

@ -53,7 +53,7 @@ class CommentLabel(DatabaseModel):
label: CommentLabelOption,
weight: float,
reason: Optional[str] = None,
) -> None:
):
"""Add a new label to a comment."""
# pylint: disable=too-many-arguments
self.comment_id = comment.comment_id

2
tildes/tildes/models/comment/comment_notification.py

@ -52,7 +52,7 @@ class CommentNotification(DatabaseModel):
def __init__(
self, user: User, comment: Comment, notification_type: CommentNotificationType
) -> None:
):
"""Create a new notification for a user from a comment."""
self.user = user
self.comment = comment

2
tildes/tildes/models/comment/comment_notification_query.py

@ -17,7 +17,7 @@ from .comment_vote import CommentVote
class CommentNotificationQuery(PaginatedQuery):
"""Specialized query class for CommentNotifications."""
def __init__(self, request: Request) -> None:
def __init__(self, request: Request):
"""Initialize a CommentNotificationQuery for the request."""
super().__init__(CommentNotification, request)

2
tildes/tildes/models/comment/comment_query.py

@ -15,7 +15,7 @@ from .comment_vote import CommentVote
class CommentQuery(PaginatedQuery):
"""Specialized ModelQuery for Comments."""
def __init__(self, request: Request) -> None:
def __init__(self, request: Request):
"""Initialize a CommentQuery for the request.
If the user is logged in, additional user-specific data will be fetched along

4
tildes/tildes/models/comment/comment_tree.py

@ -23,7 +23,7 @@ class CommentTree:
comments: Sequence[Comment],
sort: CommentSortOption,
viewer: Optional[User] = None,
) -> None:
):
"""Create a sorted CommentTree from a flat list of Comments."""
self.tree: List[CommentInTree] = []
self.sort = sort
@ -225,7 +225,7 @@ class CommentTree:
class CommentInTree(ObjectProxy):
"""Wrapper for Comments inside a CommentTree that adds some methods/properties."""
def __init__(self, comment: Comment) -> None:
def __init__(self, comment: Comment):
"""Wrap a comment and add the new attributes needed by CommentTree."""
super().__init__(comment)

2
tildes/tildes/models/comment/comment_vote.py

@ -42,7 +42,7 @@ class CommentVote(DatabaseModel):
user: User = relationship("User", innerjoin=True)
comment: Comment = relationship("Comment", innerjoin=True)
def __init__(self, user: User, comment: Comment) -> None:
def __init__(self, user: User, comment: Comment):
"""Create a new vote on a comment."""
self.user = user
self.comment = comment

2
tildes/tildes/models/group/group.py

@ -65,7 +65,7 @@ class Group(DatabaseModel):
"""Order groups by their string representation."""
return str(self) < str(other)
def __init__(self, path: str, short_desc: Optional[str] = None) -> None:
def __init__(self, path: str, short_desc: Optional[str] = None):
"""Create a new group."""
self.path = path
self.short_description = short_desc

2
tildes/tildes/models/group/group_query.py

@ -15,7 +15,7 @@ from .group_subscription import GroupSubscription
class GroupQuery(ModelQuery):
"""Specialized ModelQuery for Groups."""
def __init__(self, request: Request) -> None:
def __init__(self, request: Request):
"""Initialize a GroupQuery for the request.
If the user is logged in, additional user-specific data will be fetched along

2
tildes/tildes/models/group/group_subscription.py

@ -42,7 +42,7 @@ class GroupSubscription(DatabaseModel):
user: User = relationship("User", innerjoin=True, backref="subscriptions")
group: Group = relationship("Group", innerjoin=True, lazy=False)
def __init__(self, user: User, group: Group) -> None:
def __init__(self, user: User, group: Group):
"""Create a new subscription to a group."""
self.user = user
self.group = group

6
tildes/tildes/models/log/log.py

@ -77,7 +77,7 @@ class Log(DatabaseModel, BaseLog):
event_type: LogEventType,
request: Request,
info: Optional[Dict[str, Any]] = None,
) -> None:
):
"""Create a new log entry.
User and IP address info is extracted from the Request object. `info` is an
@ -108,7 +108,7 @@ class LogComment(DatabaseModel, BaseLog):
request: Request,
comment: Comment,
info: Optional[Dict[str, Any]] = None,
) -> None:
):
"""Create a new log entry related to a specific comment."""
# pylint: disable=non-parent-init-called
Log.__init__(self, event_type, request, info)
@ -137,7 +137,7 @@ class LogTopic(DatabaseModel, BaseLog):
request: Request,
topic: Topic,
info: Optional[Dict[str, Any]] = None,
) -> None:
):
"""Create a new log entry related to a specific topic."""
# pylint: disable=non-parent-init-called
Log.__init__(self, event_type, request, info)

8
tildes/tildes/models/message/message.py

@ -109,9 +109,7 @@ class MessageConversation(DatabaseModel):
),
)
def __init__(
self, sender: User, recipient: User, subject: str, markdown: str
) -> None:
def __init__(self, sender: User, recipient: User, subject: str, markdown: str):
"""Create a new message conversation between two users."""
self.sender_id = sender.user_id
self.recipient_id = recipient.user_id
@ -235,9 +233,7 @@ class MessageReply(DatabaseModel):
sender: User = relationship("User", lazy=False, innerjoin=True)
def __init__(
self, conversation: MessageConversation, sender: User, markdown: str
) -> None:
def __init__(self, conversation: MessageConversation, sender: User, markdown: str):
"""Add a new reply to a message conversation."""
self.conversation_id = conversation.conversation_id
self.sender_id = sender.user_id

2
tildes/tildes/models/model_query.py

@ -18,7 +18,7 @@ ModelType = TypeVar("ModelType")
class ModelQuery(Query):
"""Class for querying models via request.query()."""
def __init__(self, model_cls: Any, request: Request) -> None:
def __init__(self, model_cls: Any, request: Request):
"""Initialize a ModelQuery for the specified model and request."""
super().__init__(model_cls, session=request.db_session)

4
tildes/tildes/models/pagination.py

@ -18,7 +18,7 @@ ModelType = TypeVar("ModelType")
class PaginatedQuery(ModelQuery):
"""ModelQuery subclass that supports being split into pages."""
def __init__(self, model_cls: Any, request: Request) -> None:
def __init__(self, model_cls: Any, request: Request):
"""Initialize a PaginatedQuery for the specified model and request."""
super().__init__(model_cls, request)
@ -168,7 +168,7 @@ class PaginatedResults:
Has a few extra attributes that give info about the pagination.
"""
def __init__(self, query: PaginatedQuery, per_page: int) -> None:
def __init__(self, query: PaginatedQuery, per_page: int):
"""Fetch results from a PaginatedQuery."""
self.per_page = per_page

2
tildes/tildes/models/scraper/scraper_result.py

@ -30,7 +30,7 @@ class ScraperResult(DatabaseModel):
)
data: Any = Column(JSONB(none_as_null=True))
def __init__(self, url: str, scraper_type: ScraperType, data: Any) -> None:
def __init__(self, url: str, scraper_type: ScraperType, data: Any):
"""Create a new ScraperResult."""
self.url = url
self.scraper_type = scraper_type

2
tildes/tildes/models/topic/topic_query.py

@ -22,7 +22,7 @@ from .topic_vote import TopicVote
class TopicQuery(PaginatedQuery):
"""Specialized query class for Topics."""
def __init__(self, request: Request) -> None:
def __init__(self, request: Request):
"""Initialize a TopicQuery for the request.
If the user is logged in, additional user-specific data will be fetched along

2
tildes/tildes/models/topic/topic_vote.py

@ -42,7 +42,7 @@ class TopicVote(DatabaseModel):
user: User = relationship("User", innerjoin=True)
topic: Topic = relationship("Topic", innerjoin=True)
def __init__(self, user: User, topic: Topic) -> None:
def __init__(self, user: User, topic: Topic):
"""Create a new vote on a topic."""
self.user = user
self.topic = topic

2
tildes/tildes/models/user/user.py

@ -123,7 +123,7 @@ class User(DatabaseModel):
"""Use the username for the string representation."""
return self.username
def __init__(self, username: str, password: str) -> None:
def __init__(self, username: str, password: str):
"""Create a new user account."""
self.username = username
self.password = password

2
tildes/tildes/models/user/user_invite_code.py

@ -42,7 +42,7 @@ class UserInviteCode(DatabaseModel):
"""Format the code into a more easily readable version."""
return separate_string(self.code, "-", 5)
def __init__(self, user: User) -> None:
def __init__(self, user: User):
"""Create a new (random) invite code owned by the user.
Note that uniqueness is not confirmed here, so there is the potential to create

2
tildes/tildes/routes.py

@ -176,6 +176,6 @@ class LoggedInFactory:
__acl__ = ((Allow, Authenticated, "view"),)
def __init__(self, request: Request) -> None:
def __init__(self, request: Request):
"""Initialize - no-op, but needs to take the request as an arg."""
pass

8
tildes/tildes/schemas/fields.py

@ -19,9 +19,7 @@ from tildes.lib.string import simplify_string
class Enum(Field):
"""Field for a native Python Enum (or subclasses)."""
def __init__(
self, enum_class: Optional[Type] = None, *args: Any, **kwargs: Any
) -> None:
def __init__(self, enum_class: Optional[Type] = None, *args: Any, **kwargs: Any):
"""Initialize the field with an optional enum class."""
# pylint: disable=keyword-arg-before-vararg
super().__init__(*args, **kwargs)
@ -83,7 +81,7 @@ class Markdown(Field):
DEFAULT_MAX_LENGTH = 50000
def __init__(self, max_length: Optional[int] = None, **kwargs: Any) -> None:
def __init__(self, max_length: Optional[int] = None, **kwargs: Any):
"""Initialize the field with a length validator."""
if not max_length:
max_length = self.DEFAULT_MAX_LENGTH
@ -121,7 +119,7 @@ class SimpleString(Field):
DEFAULT_MAX_LENGTH = 200
def __init__(self, max_length: Optional[int] = None, **kwargs: Any) -> None:
def __init__(self, max_length: Optional[int] = None, **kwargs: Any):
"""Initialize the field with a length validator."""
if not max_length:
max_length = self.DEFAULT_MAX_LENGTH

2
tildes/tildes/scrapers/embedly_scraper.py

@ -15,7 +15,7 @@ from tildes.models.scraper import ScraperResult
class EmbedlyScraper:
"""Scraper that uses Embedly's "Extract" API."""
def __init__(self, api_key: str) -> None:
def __init__(self, api_key: str):
"""Create a new scraper using the specified Embedly API key."""
self.api_key = api_key

Loading…
Cancel
Save