From 7b3dfef73251a78aa2bd2e509e65b4f1be10e101 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 7 Aug 2024 14:09:42 -0400 Subject: [PATCH] Apply Ruff's flake8-type-checking (TCH) rules --- doorcontrol/views.py | 5 ++++- membershipworks/models.py | 2 +- paperwork/views.py | 5 ++++- pyproject.toml | 1 + reservations/models.py | 7 +++++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/doorcontrol/views.py b/doorcontrol/views.py index dd651be..c9ceebf 100644 --- a/doorcontrol/views.py +++ b/doorcontrol/views.py @@ -1,8 +1,8 @@ import datetime +from typing import TYPE_CHECKING from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.exceptions import BadRequest -from django.core.paginator import Page from django.db.models import Count, F, FloatField, Q, Window from django.db.models.functions import Lead, Trunc from django.urls import path, reverse_lazy @@ -27,6 +27,9 @@ from .tables import ( UnitTimeTable, ) +if TYPE_CHECKING: + from django.core.paginator import Page + REPORTS = [] diff --git a/membershipworks/models.py b/membershipworks/models.py index 59f216a..0e8b456 100644 --- a/membershipworks/models.py +++ b/membershipworks/models.py @@ -1,6 +1,5 @@ import uuid from datetime import datetime, timedelta -from decimal import Decimal from typing import TYPE_CHECKING, TypedDict import django.core.mail.message @@ -596,6 +595,7 @@ class EventExt(Event): if TYPE_CHECKING: + from decimal import Decimal class EventExtAnnotations(TypedDict): meetings: int diff --git a/paperwork/views.py b/paperwork/views.py index 4ef7148..922bb16 100644 --- a/paperwork/views.py +++ b/paperwork/views.py @@ -1,4 +1,4 @@ -from collections.abc import Iterable +from typing import TYPE_CHECKING from django.conf import settings from django.contrib.auth.decorators import login_required @@ -44,6 +44,9 @@ from .tables import ( WaiverReportTable, ) +if TYPE_CHECKING: + from collections.abc import Iterable + WIKI_URL = settings.WIKI_URL diff --git a/pyproject.toml b/pyproject.toml index 39ece58..b06b774 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,6 +80,7 @@ select = [ "PIE", "LOG", "RSE", + "TCH", ] ignore = ["ISC001"] diff --git a/reservations/models.py b/reservations/models.py index 5dd972c..a2bf070 100644 --- a/reservations/models.py +++ b/reservations/models.py @@ -1,7 +1,6 @@ from __future__ import annotations -from collections.abc import Iterable -from datetime import datetime +from typing import TYPE_CHECKING from django.contrib.auth import get_user_model from django.db import models @@ -10,6 +9,10 @@ from django.utils import timezone from model_utils.managers import InheritanceQuerySetMixin +if TYPE_CHECKING: + from collections.abc import Iterable + from datetime import datetime + class Resource(models.Model): name = models.CharField(max_length=256)