From a78bb7722c123d3f4c358a8019050e8979a13b2f Mon Sep 17 00:00:00 2001 From: sco1 Date: Wed, 18 Sep 2019 14:28:25 -0700 Subject: Update dependencies & relock --- Pipfile | 30 +++++++++++++++------------- Pipfile.lock | 65 +++++++++++++++++++++++++++++++++--------------------------- 2 files changed, 52 insertions(+), 43 deletions(-) diff --git a/Pipfile b/Pipfile index 897d1b08..2346ae99 100644 --- a/Pipfile +++ b/Pipfile @@ -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" @@ -34,6 +20,22 @@ pygments = "~=2.3.1" wiki = {git = "https://github.com/python-discord/django-wiki.git"} 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 c77efb32..c9cd758f 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "6db9cd90e14c74c0f9ae0d714df163ad4e8fcd2795a3c333b296b467f2ce2d09" + "sha256": "db7c552ce1bfd18819d21f7c2832c19f007d210d292dbaac158e47f2a1e18295" }, "pipfile-spec": 6, "requires": { @@ -18,10 +18,10 @@ "default": { "certifi": { "hashes": [ - "sha256:046832c04d4e752f37383b628bc601a7ea7211496b4638f6514d0e5b9acc4939", - "sha256:945e3ba63a0b9f577b1395204e13c3a231f9bc0223888be653286534e5873695" + "sha256:e4f3620cfea4f83eedc95b24abd9cd56f3c4b146dd0177e83a21b4eb49e21e50", + "sha256:fd7c7c74727ddcf00e9acd26bba8da604ffec95bf1c2144e67aff7a8b50e6cef" ], - "version": "==2019.6.16" + "version": "==2019.9.11" }, "chardet": { "hashes": [ @@ -267,14 +267,6 @@ ], "version": "==2.0.1" }, - "colorama": { - "hashes": [ - "sha256:05eed71e2e327246ad6b38c540c4a3117230b19679b875190486ddd2d721422d", - "sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48" - ], - "markers": "platform_system == 'Windows'", - "version": "==0.4.1" - }, "coverage": { "hashes": [ "sha256:08907593569fe59baca0bf152c43f3863201efb6113ecb38ce7e97ce339805a6", @@ -328,6 +320,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", @@ -338,11 +338,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": [ @@ -383,6 +383,13 @@ "index": "pypi", "version": "==2.0.0" }, + "flake8-todo": { + "hashes": [ + "sha256:6e4c5491ff838c06fe5a771b0e95ee15fc005ca57196011011280fc834a85915" + ], + "index": "pypi", + "version": "==0.7" + }, "gitdb2": { "hashes": [ "sha256:83361131a1836661a155172932a13c08bda2db3674e4caa32368aa6eb02f38c2", @@ -406,10 +413,10 @@ }, "importlib-metadata": { "hashes": [ - "sha256:9ff1b1c5a354142de080b8a4e9803e5d0d59283c93aed808617c787d16768375", - "sha256:b7143592e374e50584564794fcb8aaf00a23025f9db866627f89a21491847a8d" + "sha256:aa18d7378b00b40847790e7c27e11673d7fed219354109d0e7b9e5b25dc3ad26", + "sha256:d5f18a79777f3aa179c145737780282e27b508fc8fd688cb17c7a813e8bd39af" ], - "version": "==0.20" + "version": "==0.23" }, "mccabe": { "hashes": [ @@ -434,10 +441,10 @@ }, "pbr": { "hashes": [ - "sha256:56e52299170b9492513c64be44736d27a512fa7e606f21942160b68ce510b4bc", - "sha256:9b321c204a88d8ab5082699469f52cc94c5da45c51f114113d01b3d993c24cdf" + "sha256:2c8e420cd4ed4cec4e7999ee47409e876af575d4c35a45840d59e8b5f3155ab8", + "sha256:b32c8ccaac7b1a20c0ce00ce317642e6cf231cf038f9875e0280e28af5bf7ac9" ], - "version": "==5.4.2" + "version": "==5.4.3" }, "pep8-naming": { "hashes": [ @@ -449,11 +456,11 @@ }, "pre-commit": { "hashes": [ - "sha256:92e406d556190503630fd801958379861c94884693a032ba66629d0351fdccd4", - "sha256:cccc39051bc2457b0c0f7152a411f8e05e3ba2fe1a5613e4ee0833c1c1985ce3" + "sha256:1d3c0587bda7c4e537a46c27f2c84aa006acc18facf9970bf947df596ce91f3f", + "sha256:fa78ff96e8e9ac94c748388597693f18b041a181c94a4f039ad20f45287ba44a" ], "index": "pypi", - "version": "==1.17.0" + "version": "==1.18.3" }, "pycodestyle": { "hashes": [ @@ -511,16 +518,16 @@ }, "snowballstemmer": { "hashes": [ - "sha256:9f3b9ffe0809d174f7047e121431acf99c89a7040f0ca84f94ba53a498e6d0c9" + "sha256:713e53b79cbcf97bc5245a06080a33d54a77e7cce2f789c835a143bcdb5c033e" ], - "version": "==1.9.0" + "version": "==1.9.1" }, "stevedore": { "hashes": [ - "sha256:7be098ff53d87f23d798a7ce7ae5c31f094f3deb92ba18059b1aeb1ca9fec0a0", - "sha256:7d1ce610a87d26f53c087da61f06f9b7f7e552efad2a7f6d2322632b5f932ea2" + "sha256:01d9f4beecf0fbd070ddb18e5efb10567801ba7ef3ddab0074f54e3cd4e91730", + "sha256:e0739f9739a681c7a1fda76a102b65295e96a144ccdb552f2ae03c5f0abe8a14" ], - "version": "==1.30.1" + "version": "==1.31.0" }, "toml": { "hashes": [ -- cgit v1.2.3 From 609d6c0a48170e8eeefca2c6f0fd55c014c7ad65 Mon Sep 17 00:00:00 2001 From: sco1 Date: Wed, 18 Sep 2019 15:46:36 -0700 Subject: Update linting rules & partially relint --- .flake8 | 16 +++++++------- pydis_site/apps/api/dblogger.py | 2 +- pydis_site/apps/api/models/__init__.py | 7 +++--- pydis_site/apps/api/models/bot/__init__.py | 25 +++++++++++----------- pydis_site/apps/api/models/bot/bot_setting.py | 2 +- pydis_site/apps/api/models/bot/tag.py | 10 ++++----- pydis_site/apps/api/models/bot/user.py | 2 +- pydis_site/apps/api/views.py | 2 +- pydis_site/apps/api/viewsets/__init__.py | 5 +++-- pydis_site/apps/api/viewsets/bot/__init__.py | 21 +++++++++--------- pydis_site/apps/home/templatetags/extra_filters.py | 2 +- pydis_site/apps/home/templatetags/wiki_extra.py | 10 ++++----- pydis_site/utils/resources.py | 6 ++++-- 13 files changed, 58 insertions(+), 52 deletions(-) diff --git a/.flake8 b/.flake8 index 605bc46e..0f1a77e2 100644 --- a/.flake8 +++ b/.flake8 @@ -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"" @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"" @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: -- cgit v1.2.3 From ccb3d09aa88f18b91fb85198a31d82832574a656 Mon Sep 17 00:00:00 2001 From: sco1 Date: Wed, 18 Sep 2019 18:26:47 -0700 Subject: Lint remaining files --- pydis_site/apps/api/serializers.py | 8 ++++---- pydis_site/apps/api/viewsets/bot/infraction.py | 11 ++++++----- pydis_site/apps/api/viewsets/bot/nomination.py | 5 +++-- pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py | 10 ++++++---- 4 files changed, 19 insertions(+), 15 deletions(-) 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/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. -- cgit v1.2.3 From 9d550ec2ed6748d9abd05c4429cb180965b82d60 Mon Sep 17 00:00:00 2001 From: sco1 Date: Wed, 18 Sep 2019 18:36:55 -0700 Subject: Add manage.py to linting ignore Synchronize output of `pipenv run lint` and `python -m flake8` for the current project structure --- .flake8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.flake8 b/.flake8 index 0f1a77e2..66051658 100644 --- a/.flake8 +++ b/.flake8 @@ -3,7 +3,7 @@ max-line-length=100 docstring-convention=all import-order-style=pycharm application_import_names=pydis_site -exclude=__pycache__, venv, .venv, **/migrations +exclude=__pycache__, venv, .venv, manage.py, **/migrations ignore= B311,W503,E226,S311,T000 # Missing Docstrings -- cgit v1.2.3 From 7f799b6ee545a26c3ccc6f087946da54aea11430 Mon Sep 17 00:00:00 2001 From: "S. Co1" Date: Sun, 22 Sep 2019 06:51:55 -0700 Subject: Apply suggestions from code review Co-Authored-By: Mark Co-Authored-By: Sebastiaan Zeeff <33516116+SebastiaanZ@users.noreply.github.com> --- .flake8 | 2 +- pydis_site/apps/api/models/bot/tag.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.flake8 b/.flake8 index 66051658..e36c2eb1 100644 --- a/.flake8 +++ b/.flake8 @@ -17,4 +17,4 @@ ignore= # Type Annotations TYP002,TYP003,TYP101,TYP102,TYP204,TYP206 per-file-ignores = - **/tests/**:D101,D102,D103,D105,D106,S106,TYP + **/tests/**:D1,S106,TYP diff --git a/pydis_site/apps/api/models/bot/tag.py b/pydis_site/apps/api/models/bot/tag.py index 792e6b43..5435ee48 100644 --- a/pydis_site/apps/api/models/bot/tag.py +++ b/pydis_site/apps/api/models/bot/tag.py @@ -42,7 +42,7 @@ def validate_tag_embed_fields(fields: dict) -> None: validator(value) -def validate_tag_embed_footer(footer: Any) -> None: +def validate_tag_embed_footer(footer: Dict[str, str]) -> None: """Raises a ValidationError if the given footer is invalid.""" field_validators = { 'text': ( -- cgit v1.2.3 From 5d5ce4b87f138d2ba3ca2be36cf92f0bc8793ca4 Mon Sep 17 00:00:00 2001 From: "S. Co1" Date: Tue, 24 Sep 2019 13:52:32 -0400 Subject: Apply suggestions from code review Co-Authored-By: Mark --- pydis_site/apps/api/models/bot/tag.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pydis_site/apps/api/models/bot/tag.py b/pydis_site/apps/api/models/bot/tag.py index 5435ee48..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, Dict, List, Union +from typing import Any, Dict from django.contrib.postgres import fields as pgfields from django.core.exceptions import ValidationError @@ -93,7 +93,7 @@ def validate_tag_embed_author(author: Any) -> None: validator(value) -def validate_tag_embed(embed: Dict[str, Union[str, List[dict], dict]]) -> None: +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: Dict[str, Union[str, List[dict], dict]]) -> None: ... 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: -- cgit v1.2.3