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" 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.""" """Initialize the consumer, including the public suffix list."""
super().__init__(queue_name, routing_keys) 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): class TopicEmbedlyExtractor(PgsqlQueueConsumer):
"""Consumer that fetches data from Embedly's Extract API for link topics.""" """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.""" """Initialize the consumer, including creating a scraper instance."""
super().__init__(queue_name, routing_keys) 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): class TopicMetadataGenerator(PgsqlQueueConsumer):
"""Consumer that generates content_metadata for topics.""" """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.""" """Initialize the consumer, including the public suffix list."""
super().__init__(queue_name, routing_keys) 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: class DataCleaner:
"""Container class for all methods related to cleaning up old data.""" """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.""" """Create a new DataCleaner."""
self.db_session = db_session self.db_session = db_session
self.retention_cutoff = datetime.now() - retention_period self.retention_cutoff = datetime.now() - retention_period

2
tildes/tildes/api.py

@ -15,7 +15,7 @@ class APIv0(Service):
name_prefix = "apiv0_" name_prefix = "apiv0_"
base_path = "/api/v0" 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.""" """Create a new service."""
name = self.name_prefix + name name = self.name_prefix + name
path = self.base_path + path path = self.base_path + path

2
tildes/tildes/auth.py

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

2
tildes/tildes/lib/amqp.py

@ -30,7 +30,7 @@ class PgsqlQueueConsumer(AbstractConsumer):
def __init__( def __init__(
self, queue_name: str, routing_keys: Sequence[str], uses_db: bool = True self, queue_name: str, routing_keys: Sequence[str], uses_db: bool = True
) -> None:
):
"""Initialize a new queue, bindings, and consumer for it.""" """Initialize a new queue, bindings, and consumer for it."""
self.connection = Connection() self.connection = Connection()
self.channel = self.connection.channel() 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) _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.""" """Initialize a SimpleHoursPeriod from a number of hours."""
if hours <= 0: if hours <= 0:
raise ValueError("Period must be at least 1 hour.") raise ValueError("Period must be at least 1 hour.")

2
tildes/tildes/lib/markdown.py

@ -298,7 +298,7 @@ class LinkifyFilter(Filter):
def __init__( def __init__(
self, source: NonRecursiveTreeWalker, skip_tags: Optional[List[str]] = None self, source: NonRecursiveTreeWalker, skip_tags: Optional[List[str]] = None
) -> None:
):
"""Initialize a linkification filter to apply to HTML. """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 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, remaining_limit: int,
time_until_max: timedelta, time_until_max: timedelta,
time_until_retry: Optional[timedelta] = None, time_until_retry: Optional[timedelta] = None,
) -> None:
):
"""Initialize a RateLimitResult.""" """Initialize a RateLimitResult."""
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
if is_allowed and time_until_retry is not None: if is_allowed and time_until_retry is not None:
@ -171,7 +171,7 @@ class RateLimitedAction:
by_user: bool = True, by_user: bool = True,
by_ip: bool = True, by_ip: bool = True,
redis: Optional[StrictRedis] = None, redis: Optional[StrictRedis] = None,
) -> None:
):
"""Initialize the limits on a particular action. """Initialize the limits on a particular action.
The action will be limited to a maximum of `limit` calls over the time period 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, author: User,
markdown: str, markdown: str,
parent_comment: Optional["Comment"] = None, parent_comment: Optional["Comment"] = None,
) -> None:
):
"""Create a new comment.""" """Create a new comment."""
self.topic = topic self.topic = topic
self.user_id = author.user_id self.user_id = author.user_id

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

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

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

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

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

@ -17,7 +17,7 @@ from .comment_vote import CommentVote
class CommentNotificationQuery(PaginatedQuery): class CommentNotificationQuery(PaginatedQuery):
"""Specialized query class for CommentNotifications.""" """Specialized query class for CommentNotifications."""
def __init__(self, request: Request) -> None:
def __init__(self, request: Request):
"""Initialize a CommentNotificationQuery for the request.""" """Initialize a CommentNotificationQuery for the request."""
super().__init__(CommentNotification, 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): class CommentQuery(PaginatedQuery):
"""Specialized ModelQuery for Comments.""" """Specialized ModelQuery for Comments."""
def __init__(self, request: Request) -> None:
def __init__(self, request: Request):
"""Initialize a CommentQuery for the request. """Initialize a CommentQuery for the request.
If the user is logged in, additional user-specific data will be fetched along 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], comments: Sequence[Comment],
sort: CommentSortOption, sort: CommentSortOption,
viewer: Optional[User] = None, viewer: Optional[User] = None,
) -> None:
):
"""Create a sorted CommentTree from a flat list of Comments.""" """Create a sorted CommentTree from a flat list of Comments."""
self.tree: List[CommentInTree] = [] self.tree: List[CommentInTree] = []
self.sort = sort self.sort = sort
@ -225,7 +225,7 @@ class CommentTree:
class CommentInTree(ObjectProxy): class CommentInTree(ObjectProxy):
"""Wrapper for Comments inside a CommentTree that adds some methods/properties.""" """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.""" """Wrap a comment and add the new attributes needed by CommentTree."""
super().__init__(comment) super().__init__(comment)

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

@ -42,7 +42,7 @@ class CommentVote(DatabaseModel):
user: User = relationship("User", innerjoin=True) user: User = relationship("User", innerjoin=True)
comment: Comment = relationship("Comment", 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.""" """Create a new vote on a comment."""
self.user = user self.user = user
self.comment = comment self.comment = comment

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

@ -65,7 +65,7 @@ class Group(DatabaseModel):
"""Order groups by their string representation.""" """Order groups by their string representation."""
return str(self) < str(other) 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.""" """Create a new group."""
self.path = path self.path = path
self.short_description = short_desc 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): class GroupQuery(ModelQuery):
"""Specialized ModelQuery for Groups.""" """Specialized ModelQuery for Groups."""
def __init__(self, request: Request) -> None:
def __init__(self, request: Request):
"""Initialize a GroupQuery for the request. """Initialize a GroupQuery for the request.
If the user is logged in, additional user-specific data will be fetched along 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") user: User = relationship("User", innerjoin=True, backref="subscriptions")
group: Group = relationship("Group", innerjoin=True, lazy=False) 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.""" """Create a new subscription to a group."""
self.user = user self.user = user
self.group = group self.group = group

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

@ -77,7 +77,7 @@ class Log(DatabaseModel, BaseLog):
event_type: LogEventType, event_type: LogEventType,
request: Request, request: Request,
info: Optional[Dict[str, Any]] = None, info: Optional[Dict[str, Any]] = None,
) -> None:
):
"""Create a new log entry. """Create a new log entry.
User and IP address info is extracted from the Request object. `info` is an User and IP address info is extracted from the Request object. `info` is an
@ -108,7 +108,7 @@ class LogComment(DatabaseModel, BaseLog):
request: Request, request: Request,
comment: Comment, comment: Comment,
info: Optional[Dict[str, Any]] = None, info: Optional[Dict[str, Any]] = None,
) -> None:
):
"""Create a new log entry related to a specific comment.""" """Create a new log entry related to a specific comment."""
# pylint: disable=non-parent-init-called # pylint: disable=non-parent-init-called
Log.__init__(self, event_type, request, info) Log.__init__(self, event_type, request, info)
@ -137,7 +137,7 @@ class LogTopic(DatabaseModel, BaseLog):
request: Request, request: Request,
topic: Topic, topic: Topic,
info: Optional[Dict[str, Any]] = None, info: Optional[Dict[str, Any]] = None,
) -> None:
):
"""Create a new log entry related to a specific topic.""" """Create a new log entry related to a specific topic."""
# pylint: disable=non-parent-init-called # pylint: disable=non-parent-init-called
Log.__init__(self, event_type, request, info) 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.""" """Create a new message conversation between two users."""
self.sender_id = sender.user_id self.sender_id = sender.user_id
self.recipient_id = recipient.user_id self.recipient_id = recipient.user_id
@ -235,9 +233,7 @@ class MessageReply(DatabaseModel):
sender: User = relationship("User", lazy=False, innerjoin=True) 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.""" """Add a new reply to a message conversation."""
self.conversation_id = conversation.conversation_id self.conversation_id = conversation.conversation_id
self.sender_id = sender.user_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 ModelQuery(Query):
"""Class for querying models via request.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.""" """Initialize a ModelQuery for the specified model and request."""
super().__init__(model_cls, session=request.db_session) super().__init__(model_cls, session=request.db_session)

4
tildes/tildes/models/pagination.py

@ -18,7 +18,7 @@ ModelType = TypeVar("ModelType")
class PaginatedQuery(ModelQuery): class PaginatedQuery(ModelQuery):
"""ModelQuery subclass that supports being split into pages.""" """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.""" """Initialize a PaginatedQuery for the specified model and request."""
super().__init__(model_cls, request) super().__init__(model_cls, request)
@ -168,7 +168,7 @@ class PaginatedResults:
Has a few extra attributes that give info about the pagination. 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.""" """Fetch results from a PaginatedQuery."""
self.per_page = per_page 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)) 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.""" """Create a new ScraperResult."""
self.url = url self.url = url
self.scraper_type = scraper_type 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): class TopicQuery(PaginatedQuery):
"""Specialized query class for Topics.""" """Specialized query class for Topics."""
def __init__(self, request: Request) -> None:
def __init__(self, request: Request):
"""Initialize a TopicQuery for the request. """Initialize a TopicQuery for the request.
If the user is logged in, additional user-specific data will be fetched along 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) user: User = relationship("User", innerjoin=True)
topic: Topic = relationship("Topic", 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.""" """Create a new vote on a topic."""
self.user = user self.user = user
self.topic = topic self.topic = topic

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

@ -123,7 +123,7 @@ class User(DatabaseModel):
"""Use the username for the string representation.""" """Use the username for the string representation."""
return self.username return self.username
def __init__(self, username: str, password: str) -> None:
def __init__(self, username: str, password: str):
"""Create a new user account.""" """Create a new user account."""
self.username = username self.username = username
self.password = password 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.""" """Format the code into a more easily readable version."""
return separate_string(self.code, "-", 5) 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. """Create a new (random) invite code owned by the user.
Note that uniqueness is not confirmed here, so there is the potential to create 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"),) __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.""" """Initialize - no-op, but needs to take the request as an arg."""
pass pass

8
tildes/tildes/schemas/fields.py

@ -19,9 +19,7 @@ from tildes.lib.string import simplify_string
class Enum(Field): class Enum(Field):
"""Field for a native Python Enum (or subclasses).""" """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.""" """Initialize the field with an optional enum class."""
# pylint: disable=keyword-arg-before-vararg # pylint: disable=keyword-arg-before-vararg
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -83,7 +81,7 @@ class Markdown(Field):
DEFAULT_MAX_LENGTH = 50000 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.""" """Initialize the field with a length validator."""
if not max_length: if not max_length:
max_length = self.DEFAULT_MAX_LENGTH max_length = self.DEFAULT_MAX_LENGTH
@ -121,7 +119,7 @@ class SimpleString(Field):
DEFAULT_MAX_LENGTH = 200 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.""" """Initialize the field with a length validator."""
if not max_length: if not max_length:
max_length = self.DEFAULT_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: class EmbedlyScraper:
"""Scraper that uses Embedly's "Extract" API.""" """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.""" """Create a new scraper using the specified Embedly API key."""
self.api_key = api_key self.api_key = api_key

Loading…
Cancel
Save