From d995b412a06bfee582275f1554d490c3581a1ec1 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 28 Jul 2022 20:15:20 +0100 Subject: [PATCH] Remove django-stubs It's just not quite there yet for a lot of things, and makes certain things a right pain! --- requirements/dev.in | 2 +- requirements/dev.txt | 12 ++++-------- setup.cfg | 4 ---- website/blog/models.py | 20 +++++--------------- website/blog/wagtail_hooks.py | 4 +--- website/common/models.py | 2 +- website/home/models.py | 5 +---- 7 files changed, 13 insertions(+), 36 deletions(-) diff --git a/requirements/dev.in b/requirements/dev.in index a900672..a23d30e 100644 --- a/requirements/dev.in +++ b/requirements/dev.in @@ -3,10 +3,10 @@ pip-tools honcho -django-stubs[compatible-mypy] flake8 isort black django-browser-reload django-debug-toolbar types-requests +mypy diff --git a/requirements/dev.txt b/requirements/dev.txt index c98e80e..599bf7a 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -15,7 +15,7 @@ certifi==2022.6.15 # via -r requirements/base.txt, requests charset-normalizer==2.1.0 # via -r requirements/base.txt, requests click==8.1.3 # via -r requirements/base.txt, black, pip-tools, rq deprecated==1.2.13 # via -r requirements/base.txt, redis -django==4.0.6 # via -r requirements/base.txt, django-browser-reload, django-debug-toolbar, django-filter, django-modelcluster, django-permissionedforms, django-redis, django-rq, django-stubs, django-stubs-ext, django-taggit, django-treebeard, djangorestframework, wagtail +django==4.0.6 # via -r requirements/base.txt, django-browser-reload, django-debug-toolbar, django-filter, django-modelcluster, django-permissionedforms, django-redis, django-rq, django-taggit, django-treebeard, djangorestframework, wagtail django-browser-reload==1.6.0 # via -r requirements/dev.in django-debug-toolbar==3.5.0 # via -r requirements/dev.in django-environ==0.9.0 # via -r requirements/base.txt @@ -24,8 +24,6 @@ django-modelcluster==6.0 # via -r requirements/base.txt, wagtail django-permissionedforms==0.1 # via -r requirements/base.txt, wagtail django-redis==5.2.0 # via -r requirements/base.txt django-rq==2.5.1 # via -r requirements/base.txt -django-stubs[compatible-mypy]==1.12.0 # via -r requirements/dev.in -django-stubs-ext==0.5.0 # via django-stubs django-taggit==2.1.0 # via -r requirements/base.txt, wagtail django-treebeard==4.5.1 # via -r requirements/base.txt, wagtail djangorestframework==3.13.1 # via -r requirements/base.txt, wagtail @@ -41,7 +39,7 @@ l18n==2021.3 # via -r requirements/base.txt, wagtail lxml==4.9.1 # via -r requirements/base.txt mccabe==0.6.1 # via flake8 more-itertools==8.13.0 # via -r requirements/base.txt -mypy==0.961 # via django-stubs +mypy==0.971 # via -r requirements/dev.in mypy-extensions==0.4.3 # via black, mypy openpyxl==3.0.10 # via -r requirements/base.txt, tablib packaging==21.3 # via -r requirements/base.txt, build, redis @@ -63,12 +61,10 @@ soupsieve==2.3.2.post1 # via -r requirements/base.txt, beautifulsoup4 sqlparse==0.4.2 # via -r requirements/base.txt, django, django-debug-toolbar tablib[xls,xlsx]==3.2.1 # via -r requirements/base.txt, wagtail telepath==0.2 # via -r requirements/base.txt, wagtail -tomli==2.0.1 # via black, build, django-stubs, mypy -types-pytz==2022.1.2 # via django-stubs -types-pyyaml==6.0.11 # via django-stubs +tomli==2.0.1 # via black, build, mypy types-requests==2.28.5 # via -r requirements/dev.in types-urllib3==1.26.17 # via types-requests -typing-extensions==4.3.0 # via django-stubs, django-stubs-ext, mypy +typing-extensions==4.3.0 # via mypy urllib3==1.26.11 # via -r requirements/base.txt, requests wagtail==3.0.1 # via -r requirements/base.txt, wagtail-draftail-snippet wagtail-draftail-snippet==0.4.1 # via -r requirements/base.txt diff --git a/setup.cfg b/setup.cfg index 99883e6..6dceb1c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,10 +7,6 @@ ignore_missing_imports = True disallow_untyped_calls = True disallow_untyped_defs = True disallow_incomplete_defs = True -plugins = mypy_django_plugin.main - -[mypy.plugins.django-stubs] -django_settings_module = "website.settings" [isort] multi_line_output=3 diff --git a/website/blog/models.py b/website/blog/models.py index f45d994..7a05a0e 100644 --- a/website/blog/models.py +++ b/website/blog/models.py @@ -46,9 +46,7 @@ class BlogListPage(BaseContentMixin, RoutablePageMixin, BasePage): # type: igno return [TocEntry(post_month, post_month, 0, []) for post_month in post_months] def get_blog_posts(self) -> PageQuerySet: - return BlogPostPage.objects.descendant_of( # type:ignore[attr-defined] - self - ).live() + return BlogPostPage.objects.descendant_of(self).live() def get_context(self, request: HttpRequest) -> dict: context = super().get_context(request) @@ -117,9 +115,7 @@ class BlogPostTagPage(BaseContentMixin, RoutablePageMixin, BasePage): # type: i ] def get_blog_posts(self) -> PageQuerySet: - blog_list_page = ( - BlogListPage.objects.all().live().get() # type:ignore[attr-defined] - ) + blog_list_page = BlogListPage.objects.all().live().get() return blog_list_page.get_blog_posts().filter(tags=self).order_by("-date") def get_context(self, request: HttpRequest) -> dict: @@ -150,12 +146,8 @@ class BlogCollectionListPage(BaseContentMixin, BasePage): # type: ignore[misc] ] def get_collections(self) -> PageQuerySet: - blog_list_page = ( - BlogListPage.objects.all().live().get() # type:ignore[attr-defined] - ) - return BlogCollectionPage.objects.child_of( # type:ignore[attr-defined] - blog_list_page - ).live() + blog_list_page = BlogListPage.objects.all().live().get() + return BlogCollectionPage.objects.child_of(blog_list_page).live() def get_context(self, request: HttpRequest) -> dict: context = super().get_context(request) @@ -176,9 +168,7 @@ class BlogCollectionPage(BaseContentMixin, BasePage): # type: ignore[misc] ] def get_blog_posts(self) -> PageQuerySet: - return BlogPostPage.objects.child_of( # type:ignore[attr-defined] - self - ).order_by("-date") + return BlogPostPage.objects.child_of(self).order_by("-date") def get_context(self, request: HttpRequest) -> dict: context = super().get_context(request) diff --git a/website/blog/wagtail_hooks.py b/website/blog/wagtail_hooks.py index 3baa9dc..4126563 100644 --- a/website/blog/wagtail_hooks.py +++ b/website/blog/wagtail_hooks.py @@ -15,9 +15,7 @@ class BlogPostTagsMenuItem(MenuItem): def is_shown(self, request: HttpRequest) -> bool: if not self.url: blog_post_tag_list_id = ( - BlogPostTagListPage.objects.live() # type:ignore[attr-defined] - .values_list("id", flat=True) - .first() + BlogPostTagListPage.objects.live().values_list("id", flat=True).first() ) self.url = ( reverse("wagtailadmin_explore", args=[blog_post_tag_list_id]) diff --git a/website/common/models.py b/website/common/models.py index b8e3b24..52dd911 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -91,7 +91,7 @@ class BaseContentMixin(models.Model): @cached_property def hero_image_url(self) -> Optional[str]: if self.hero_unsplash_photo_id is not None: - return self.hero_unsplash_photo.get_hero_image_url() # type: ignore + return self.hero_unsplash_photo.get_hero_image_url() elif self.hero_image_id is not None: return generate_image_url(self.hero_image, "width-1200") return None diff --git a/website/home/models.py b/website/home/models.py index cb9f4cf..df5d35b 100644 --- a/website/home/models.py +++ b/website/home/models.py @@ -23,9 +23,6 @@ class HomePage(BasePage): def get_context(self, request: HttpRequest) -> dict: context = super().get_context(request) context["latest_blog_post"] = ( - BlogPostPage.objects.live() # type:ignore[attr-defined] - .defer_streamfields() - .order_by("-date") - .first() + BlogPostPage.objects.live().defer_streamfields().order_by("-date").first() ) return context