diff options
-rw-r--r-- | .flake8 | 16 | ||||
-rw-r--r-- | Pipfile | 30 | ||||
-rw-r--r-- | Pipfile.lock | 43 | ||||
-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 | 12 | ||||
-rw-r--r-- | pydis_site/apps/api/models/bot/user.py | 2 | ||||
-rw-r--r-- | pydis_site/apps/api/serializers.py | 8 | ||||
-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/api/viewsets/bot/infraction.py | 11 | ||||
-rw-r--r-- | pydis_site/apps/api/viewsets/bot/nomination.py | 5 | ||||
-rw-r--r-- | pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py | 10 | ||||
-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 |
19 files changed, 127 insertions, 92 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, manage.py, **/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/**:D1,S106,TYP @@ -3,20 +3,6 @@ name = "pypi" url = "https://pypi.org/simple" verify_ssl = true -[dev-packages] -flake8 = "~=3.7.7" -flake8-bandit = "==1.0.2" -flake8-bugbear = "~=19.3.0" -flake8-docstrings = "~=1.4.0" -flake8-import-order = "~=0.18.1" -flake8-string-format = "~=0.2.3" -flake8-tidy-imports = "~=2.0.0" -mccabe = "~=0.6.1" -pep8-naming = "~=0.8.2" -coverage = "~=4.5.3" -unittest-xml-reporting = "~=2.5.1" -pre-commit = "~=1.17.0" - [packages] django = "~=2.2" django-crispy-forms = "~=1.7.2" @@ -35,6 +21,22 @@ pygments = "~=2.3.1" wiki = {path = "./docker/app/wheels/wiki-0.5.dev20190420204942-py3-none-any.whl"} pyyaml = "*" +[dev-packages] +coverage = "~=4.5.3" +flake8 = "~=3.7" +flake8-annotations = "~=1.0" +flake8-bandit = "==1.0.2" +flake8-bugbear = "~=19.8" +flake8-docstrings = "~=1.4" +flake8-import-order = "~=0.18" +flake8-string-format = "~=0.2" +flake8-tidy-imports = "~=2.0" +flake8-todo = "~=0.7" +mccabe = "~=0.6.1" +pep8-naming = "~=0.8.2" +pre-commit = "~=1.18" +unittest-xml-reporting = "~=2.5.1" + [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock index 36059664..01345754 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "d44e1d6fdeba2a0fdda4a249ebcb4a2f8062cc4b2ba1ef2c8de017bc442571fa" + "sha256": "d0e378fcea422eb28537a91e60e7faab8ae08a4ad9e3f1bd71fe89d377d36a8d" }, "pipfile-spec": 6, "requires": { @@ -312,10 +312,10 @@ }, "urllib3": { "hashes": [ - "sha256:2f3eadfea5d92bc7899e75b5968410b749a054b492d5a6379c1344a1481bc2cb", - "sha256:9c6c593cb28f52075016307fc26b0a0f8e82bc7d1ff19aaaa959b91710a56c47" + "sha256:3de946ffbed6e6746608990594d08faac602528ac7015ac28d33cee6a45b7398", + "sha256:9a107b99a5393caf59c7aa3c1249c16e6879447533d0887f4336dde834c7be86" ], - "version": "==1.25.5" + "version": "==1.25.6" }, "webencodings": { "hashes": [ @@ -369,6 +369,14 @@ ], "version": "==2.0.1" }, + "colorama": { + "hashes": [ + "sha256:05eed71e2e327246ad6b38c540c4a3117230b19679b875190486ddd2d721422d", + "sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48" + ], + "markers": "platform_system == 'Windows'", + "version": "==0.4.1" + }, "coverage": { "hashes": [ "sha256:08907593569fe59baca0bf152c43f3863201efb6113ecb38ce7e97ce339805a6", @@ -422,6 +430,14 @@ "index": "pypi", "version": "==3.7.8" }, + "flake8-annotations": { + "hashes": [ + "sha256:1309f2bc9853a2d77d578b089d331b0b832b40c97932641e136e1b49d3650c82", + "sha256:3ecdd27054c3eed6484139025698465e3c9f4e68dbd5043d0204fcb2550ee27b" + ], + "index": "pypi", + "version": "==1.0.0" + }, "flake8-bandit": { "hashes": [ "sha256:a66c7b42af9530d5e988851ccee02958a51a85d46f1f4609ecc3546948f809b8", @@ -432,11 +448,11 @@ }, "flake8-bugbear": { "hashes": [ - "sha256:5070774b668be92c4312e5ca82748ddf4ecaa7a24ff062662681bb745c7896eb", - "sha256:fef9c9826d14ec23187ae1edeb3c6513c4e46bf0e70d86bac38f7d9aabae113d" + "sha256:d8c466ea79d5020cb20bf9f11cf349026e09517a42264f313d3f6fddb83e0571", + "sha256:ded4d282778969b5ab5530ceba7aa1a9f1b86fa7618fc96a19a1d512331640f8" ], "index": "pypi", - "version": "==19.3.0" + "version": "==19.8.0" }, "flake8-docstrings": { "hashes": [ @@ -477,6 +493,13 @@ "index": "pypi", "version": "==2.0.0" }, + "flake8-todo": { + "hashes": [ + "sha256:6e4c5491ff838c06fe5a771b0e95ee15fc005ca57196011011280fc834a85915" + ], + "index": "pypi", + "version": "==0.7" + }, "gitdb2": { "hashes": [ "sha256:83361131a1836661a155172932a13c08bda2db3674e4caa32368aa6eb02f38c2", @@ -543,11 +566,11 @@ }, "pre-commit": { "hashes": [ - "sha256:92e406d556190503630fd801958379861c94884693a032ba66629d0351fdccd4", - "sha256:cccc39051bc2457b0c0f7152a411f8e05e3ba2fe1a5613e4ee0833c1c1985ce3" + "sha256:1d3c0587bda7c4e537a46c27f2c84aa006acc18facf9970bf947df596ce91f3f", + "sha256:fa78ff96e8e9ac94c748388597693f18b041a181c94a4f039ad20f45287ba44a" ], "index": "pypi", - "version": "==1.17.0" + "version": "==1.18.3" }, "pycodestyle": { "hashes": [ 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..5d4cc393 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 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: Dict[str, str]) -> 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: Any) -> None: """ Validate a JSON document containing an embed as possible to send on Discord. @@ -120,7 +120,7 @@ def validate_tag_embed(embed): ... Args: - embed (Dict[str, Union[str, List[dict], dict]]): + embed (Any): A dictionary describing the contents of this embed. See the official documentation for a full reference of accepted keys by this dictionary: 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/serializers.py b/pydis_site/apps/api/serializers.py index 442f6209..5466b06b 100644 --- a/pydis_site/apps/api/serializers.py +++ b/pydis_site/apps/api/serializers.py @@ -66,7 +66,7 @@ class MessageDeletionContextSerializer(ModelSerializer): fields = ('actor', 'creation', 'id', 'deletedmessage_set') depth = 1 - def create(self, validated_data): + def create(self, validated_data: dict) -> MessageDeletionContext: """ Return a `MessageDeletionContext` based on the given data. @@ -106,7 +106,7 @@ class InfractionSerializer(ModelSerializer): 'id', 'inserted_at', 'expires_at', 'active', 'user', 'actor', 'type', 'reason', 'hidden' ) - def validate(self, attrs): + def validate(self, attrs: dict) -> dict: """Validate data constraints for the given data and abort if it is invalid.""" infr_type = attrs.get('type') @@ -129,7 +129,7 @@ class ExpandedInfractionSerializer(InfractionSerializer): serializer also attaches the `user` and `actor` fields when serializing. """ - def to_representation(self, instance): + def to_representation(self, instance: Infraction) -> dict: """Return the dictionary representation of this infraction.""" ret = super().to_representation(instance) @@ -166,7 +166,7 @@ class OffTopicChannelNameSerializer(ModelSerializer): model = OffTopicChannelName fields = ('name',) - def to_representation(self, obj): + def to_representation(self, obj: OffTopicChannelName) -> str: """ Return the representation of this `OffTopicChannelName`. 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/api/viewsets/bot/infraction.py b/pydis_site/apps/api/viewsets/bot/infraction.py index c471ca2c..edec0a1e 100644 --- a/pydis_site/apps/api/viewsets/bot/infraction.py +++ b/pydis_site/apps/api/viewsets/bot/infraction.py @@ -1,3 +1,4 @@ +from django.http.request import HttpRequest from django_filters.rest_framework import DjangoFilterBackend from rest_framework.decorators import action from rest_framework.exceptions import ValidationError @@ -123,7 +124,7 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge search_fields = ('$reason',) frozen_fields = ('id', 'inserted_at', 'type', 'user', 'actor', 'hidden') - def partial_update(self, request, *_args, **_kwargs): + def partial_update(self, request: HttpRequest, *_args, **_kwargs) -> Response: """Method that handles the nuts and bolts of updating an Infraction.""" for field in request.data: if field in self.frozen_fields: @@ -137,7 +138,7 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge return Response(serializer.data) @action(url_path='expanded', detail=False) - def list_expanded(self, *args, **kwargs): + def list_expanded(self, *args, **kwargs) -> Response: """ DRF method for listing Infraction entries. @@ -147,7 +148,7 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge return self.list(*args, **kwargs) @list_expanded.mapping.post - def create_expanded(self, *args, **kwargs): + def create_expanded(self, *args, **kwargs) -> Response: """ DRF method for creating an Infraction. @@ -157,7 +158,7 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge return self.create(*args, **kwargs) @action(url_path='expanded', url_name='detail-expanded', detail=True) - def retrieve_expanded(self, *args, **kwargs): + def retrieve_expanded(self, *args, **kwargs) -> Response: """ DRF method for retrieving a specific Infraction. @@ -167,7 +168,7 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge return self.retrieve(*args, **kwargs) @retrieve_expanded.mapping.patch - def partial_update_expanded(self, *args, **kwargs): + def partial_update_expanded(self, *args, **kwargs) -> Response: """ DRF method for updating an Infraction. diff --git a/pydis_site/apps/api/viewsets/bot/nomination.py b/pydis_site/apps/api/viewsets/bot/nomination.py index 8d551697..cf6e262f 100644 --- a/pydis_site/apps/api/viewsets/bot/nomination.py +++ b/pydis_site/apps/api/viewsets/bot/nomination.py @@ -1,5 +1,6 @@ from collections import ChainMap +from django.http.request import HttpRequest from django.utils import timezone from django_filters.rest_framework import DjangoFilterBackend from rest_framework import status @@ -151,7 +152,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge frozen_fields = ('id', 'actor', 'inserted_at', 'user', 'ended_at') frozen_on_create = ('ended_at', 'end_reason', 'active', 'inserted_at') - def create(self, request, *args, **kwargs): + def create(self, request: HttpRequest, *args, **kwargs) -> Response: """ DRF method for creating a Nomination. @@ -176,7 +177,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge headers = self.get_success_headers(serializer.data) return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers) - def partial_update(self, request, *args, **kwargs): + def partial_update(self, request: HttpRequest, *args, **kwargs) -> Response: """ DRF method for updating a Nomination. diff --git a/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py b/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py index d977aade..d6da2399 100644 --- a/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py +++ b/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py @@ -1,3 +1,5 @@ +from django.db.models.query import QuerySet +from django.http.request import HttpRequest from django.shortcuts import get_object_or_404 from rest_framework.exceptions import ParseError from rest_framework.mixins import DestroyModelMixin @@ -54,7 +56,7 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet): lookup_field = 'name' serializer_class = OffTopicChannelNameSerializer - def get_object(self): + def get_object(self) -> OffTopicChannelName: """ Returns the OffTopicChannelName entry for this request, if it exists. @@ -64,11 +66,11 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet): name = self.kwargs[self.lookup_field] return get_object_or_404(queryset, name=name) - def get_queryset(self): + def get_queryset(self) -> QuerySet: """Returns a queryset that covers the entire OffTopicChannelName table.""" return OffTopicChannelName.objects.all() - def create(self, request): + def create(self, request: HttpRequest) -> Response: """ DRF method for creating a new OffTopicChannelName. @@ -86,7 +88,7 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet): 'name': ["This query parameter is required."] }) - def list(self, request): + def list(self, request: HttpRequest) -> Response: """ DRF method for listing OffTopicChannelName entries. 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: |