diff options
author | 2019-09-18 15:46:36 -0700 | |
---|---|---|
committer | 2019-09-18 15:46:36 -0700 | |
commit | 609d6c0a48170e8eeefca2c6f0fd55c014c7ad65 (patch) | |
tree | cf46bf8da7478207f008c0af31005e39f0a691e3 | |
parent | Update dependencies & relock (diff) |
Update linting rules & partially relint
-rw-r--r-- | .flake8 | 16 | ||||
-rw-r--r-- | pydis_site/apps/api/dblogger.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/api/models/__init__.py | 7 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/__init__.py | 25 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/bot_setting.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/tag.py | 10 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/user.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/api/views.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/api/viewsets/__init__.py | 5 | ||||
-rw-r--r-- | pydis_site/apps/api/viewsets/bot/__init__.py | 21 | ||||
-rw-r--r-- | pydis_site/apps/home/templatetags/extra_filters.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/home/templatetags/wiki_extra.py | 10 | ||||
-rw-r--r-- | pydis_site/utils/resources.py | 6 |
13 files changed, 58 insertions, 52 deletions
@@ -1,7 +1,11 @@ [flake8] +max-line-length=100 docstring-convention=all +import-order-style=pycharm +application_import_names=pydis_site +exclude=__pycache__, venv, .venv, **/migrations ignore= - P102,B311,W503,E226,S311, + B311,W503,E226,S311,T000 # Missing Docstrings D100,D104,D105,D107, # Docstring Whitespace @@ -10,11 +14,7 @@ ignore= D301,D302, # Docstring Content D400,D401,D402,D404,D405,D406,D407,D408,D409,D410,D411,D412,D413,D414,D416,D417 - + # Type Annotations + TYP002,TYP003,TYP101,TYP102,TYP204,TYP206 per-file-ignores = - **/tests/**:D101,D102,D103,D105,D106,S106 - -application_import_names=pydis_site -exclude=__pycache__, venv, .venv, **/migrations -import-order-style=pycharm -max-line-length=100 + **/tests/**:D101,D102,D103,D105,D106,S106,TYP diff --git a/pydis_site/apps/api/dblogger.py b/pydis_site/apps/api/dblogger.py index f133832a..4b4e3a9d 100644 --- a/pydis_site/apps/api/dblogger.py +++ b/pydis_site/apps/api/dblogger.py @@ -4,7 +4,7 @@ from logging import LogRecord, StreamHandler class DatabaseLogHandler(StreamHandler): """Logs entries into the database.""" - def emit(self, record: LogRecord): + def emit(self, record: LogRecord) -> None: """Write the given `record` into the database.""" # This import needs to be deferred due to Django's application # registry instantiation logic loading this handler before the diff --git a/pydis_site/apps/api/models/__init__.py b/pydis_site/apps/api/models/__init__.py index a7eccb04..a4656bc3 100644 --- a/pydis_site/apps/api/models/__init__.py +++ b/pydis_site/apps/api/models/__init__.py @@ -1,4 +1,5 @@ -from .bot import ( # noqa +# flake8: noqa +from .bot import ( BotSetting, DocumentationLink, DeletedMessage, @@ -12,5 +13,5 @@ from .bot import ( # noqa Tag, User ) -from .log_entry import LogEntry # noqa -from .utils import ModelReprMixin # noqa +from .log_entry import LogEntry +from .utils import ModelReprMixin diff --git a/pydis_site/apps/api/models/bot/__init__.py b/pydis_site/apps/api/models/bot/__init__.py index b805924a..46219ea2 100644 --- a/pydis_site/apps/api/models/bot/__init__.py +++ b/pydis_site/apps/api/models/bot/__init__.py @@ -1,12 +1,13 @@ -from .bot_setting import BotSetting # noqa -from .deleted_message import DeletedMessage # noqa -from .documentation_link import DocumentationLink # noqa -from .infraction import Infraction # noqa -from .message import Message # noqa -from .message_deletion_context import MessageDeletionContext # noqa -from .nomination import Nomination # noqa -from .off_topic_channel_name import OffTopicChannelName # noqa -from .reminder import Reminder # noqa -from .role import Role # noqa -from .tag import Tag # noqa -from .user import User # noqa +# flake8: noqa +from .bot_setting import BotSetting +from .deleted_message import DeletedMessage +from .documentation_link import DocumentationLink +from .infraction import Infraction +from .message import Message +from .message_deletion_context import MessageDeletionContext +from .nomination import Nomination +from .off_topic_channel_name import OffTopicChannelName +from .reminder import Reminder +from .role import Role +from .tag import Tag +from .user import User diff --git a/pydis_site/apps/api/models/bot/bot_setting.py b/pydis_site/apps/api/models/bot/bot_setting.py index a52f3e34..b1c3e47c 100644 --- a/pydis_site/apps/api/models/bot/bot_setting.py +++ b/pydis_site/apps/api/models/bot/bot_setting.py @@ -5,7 +5,7 @@ from django.db import models from pydis_site.apps.api.models.utils import ModelReprMixin -def validate_bot_setting_name(name): +def validate_bot_setting_name(name: str) -> None: """Raises a ValidationError if the given name is not a known setting.""" known_settings = ( 'defcon', diff --git a/pydis_site/apps/api/models/bot/tag.py b/pydis_site/apps/api/models/bot/tag.py index de4eab30..792e6b43 100644 --- a/pydis_site/apps/api/models/bot/tag.py +++ b/pydis_site/apps/api/models/bot/tag.py @@ -1,5 +1,5 @@ from collections.abc import Mapping -from typing import Any +from typing import Any, Dict, List, Union from django.contrib.postgres import fields as pgfields from django.core.exceptions import ValidationError @@ -15,7 +15,7 @@ def is_bool_validator(value: Any) -> None: raise ValidationError(f"This field must be of type bool, not {type(value)}.") -def validate_tag_embed_fields(fields): +def validate_tag_embed_fields(fields: dict) -> None: """Raises a ValidationError if any of the given embed fields is invalid.""" field_validators = { 'name': (MaxLengthValidator(limit_value=256),), @@ -42,7 +42,7 @@ def validate_tag_embed_fields(fields): validator(value) -def validate_tag_embed_footer(footer): +def validate_tag_embed_footer(footer: Any) -> None: """Raises a ValidationError if the given footer is invalid.""" field_validators = { 'text': ( @@ -67,7 +67,7 @@ def validate_tag_embed_footer(footer): validator(value) -def validate_tag_embed_author(author): +def validate_tag_embed_author(author: Any) -> None: """Raises a ValidationError if the given author is invalid.""" field_validators = { 'name': ( @@ -93,7 +93,7 @@ def validate_tag_embed_author(author): validator(value) -def validate_tag_embed(embed): +def validate_tag_embed(embed: Dict[str, Union[str, List[dict], dict]]) -> None: """ Validate a JSON document containing an embed as possible to send on Discord. diff --git a/pydis_site/apps/api/models/bot/user.py b/pydis_site/apps/api/models/bot/user.py index 00c24d3d..21617dc4 100644 --- a/pydis_site/apps/api/models/bot/user.py +++ b/pydis_site/apps/api/models/bot/user.py @@ -8,7 +8,7 @@ from pydis_site.apps.api.models.utils import ModelReprMixin class User(ModelReprMixin, models.Model): """A Discord user.""" - id = models.BigIntegerField( # noqa + id = models.BigIntegerField( primary_key=True, validators=( MinValueValidator( diff --git a/pydis_site/apps/api/views.py b/pydis_site/apps/api/views.py index e79de5e1..32583665 100644 --- a/pydis_site/apps/api/views.py +++ b/pydis_site/apps/api/views.py @@ -56,7 +56,7 @@ class RulesView(APIView): permission_classes = () @staticmethod - def _format_link(description, link, target): + def _format_link(description: str, link: str, target: str) -> str: """ Build the markup for rendering the link. diff --git a/pydis_site/apps/api/viewsets/__init__.py b/pydis_site/apps/api/viewsets/__init__.py index 224e6910..f9a186d9 100644 --- a/pydis_site/apps/api/viewsets/__init__.py +++ b/pydis_site/apps/api/viewsets/__init__.py @@ -1,4 +1,5 @@ -from .bot import ( # noqa +# flake8: noqa +from .bot import ( BotSettingViewSet, DeletedMessageViewSet, DocumentationLinkViewSet, @@ -10,4 +11,4 @@ from .bot import ( # noqa TagViewSet, UserViewSet ) -from .log_entry import LogEntryViewSet # noqa +from .log_entry import LogEntryViewSet diff --git a/pydis_site/apps/api/viewsets/bot/__init__.py b/pydis_site/apps/api/viewsets/bot/__init__.py index 465ba5f4..f1851e32 100644 --- a/pydis_site/apps/api/viewsets/bot/__init__.py +++ b/pydis_site/apps/api/viewsets/bot/__init__.py @@ -1,10 +1,11 @@ -from .bot_setting import BotSettingViewSet # noqa -from .deleted_message import DeletedMessageViewSet # noqa -from .documentation_link import DocumentationLinkViewSet # noqa -from .infraction import InfractionViewSet # noqa -from .nomination import NominationViewSet # noqa -from .off_topic_channel_name import OffTopicChannelNameViewSet # noqa -from .reminder import ReminderViewSet # noqa -from .role import RoleViewSet # noqa -from .tag import TagViewSet # noqa -from .user import UserViewSet # noqa +# flake8: noqa +from .bot_setting import BotSettingViewSet +from .deleted_message import DeletedMessageViewSet +from .documentation_link import DocumentationLinkViewSet +from .infraction import InfractionViewSet +from .nomination import NominationViewSet +from .off_topic_channel_name import OffTopicChannelNameViewSet +from .reminder import ReminderViewSet +from .role import RoleViewSet +from .tag import TagViewSet +from .user import UserViewSet diff --git a/pydis_site/apps/home/templatetags/extra_filters.py b/pydis_site/apps/home/templatetags/extra_filters.py index 99ba3dcd..d63b3245 100644 --- a/pydis_site/apps/home/templatetags/extra_filters.py +++ b/pydis_site/apps/home/templatetags/extra_filters.py @@ -4,7 +4,7 @@ register = template.Library() @register.filter -def starts_with(value: str, arg: str): +def starts_with(value: str, arg: str) -> bool: """ Simple filter for checking if a string value starts with another string. diff --git a/pydis_site/apps/home/templatetags/wiki_extra.py b/pydis_site/apps/home/templatetags/wiki_extra.py index 2e90af43..b4b720bf 100644 --- a/pydis_site/apps/home/templatetags/wiki_extra.py +++ b/pydis_site/apps/home/templatetags/wiki_extra.py @@ -4,7 +4,7 @@ from django import template from django.forms import BooleanField, BoundField, CharField, Field, ImageField, ModelChoiceField from django.template import Context from django.template.loader import get_template -from django.utils.safestring import mark_safe +from django.utils.safestring import SafeText, mark_safe from wiki.editors.markitup import MarkItUpWidget from wiki.forms import WikiSlugField from wiki.models import URLPath @@ -39,7 +39,7 @@ def get_unbound_field(field: Union[BoundField, Field]) -> Field: return field -def render(template_path: str, context: Dict[str, Any]): +def render(template_path: str, context: Dict[str, Any]) -> SafeText: """ Renders a template at a specified path, with the provided context dictionary. @@ -50,7 +50,7 @@ def render(template_path: str, context: Dict[str, Any]): @register.simple_tag -def render_field(field: Field, render_labels: bool = True): +def render_field(field: Field, render_labels: bool = True) -> SafeText: """ Renders a form field using a custom template designed specifically for the wiki forms. @@ -78,7 +78,7 @@ def render_field(field: Field, render_labels: bool = True): @register.simple_tag(takes_context=True) -def get_field_options(context: Context, field: BoundField): +def get_field_options(context: Context, field: BoundField) -> str: """ Retrieves the field options for a multiple choice field, and stores it in the context. @@ -113,7 +113,7 @@ def get_field_options(context: Context, field: BoundField): @register.filter -def render_urlpath(value: Union[URLPath, str]): +def render_urlpath(value: Union[URLPath, str]) -> str: """ Simple filter to render a URLPath (or string) into a template. diff --git a/pydis_site/utils/resources.py b/pydis_site/utils/resources.py index fb5faef8..637fd785 100644 --- a/pydis_site/utils/resources.py +++ b/pydis_site/utils/resources.py @@ -30,7 +30,8 @@ class Resource: return f"<Resource name={self.name}>" @classmethod - def construct_from_yaml(cls, yaml_data: typing.TextIO) -> Resource: # noqa + def construct_from_yaml(cls, yaml_data: typing.TextIO) -> Resource: + """Construct a Resource object from the provided YAML.""" resource = cls() loaded = yaml.safe_load(yaml_data) @@ -57,7 +58,8 @@ class Category: return f"<Category name={self.name}>" @classmethod - def construct_from_directory(cls, directory: str) -> Category: # noqa + def construct_from_directory(cls, directory: str) -> Category: + """Construct a Category object from the provided directory.""" category = cls() with open(f"{directory}/_category_info.yaml") as category_info: |