Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve some mypy findings #367

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/meshapi/admin/inlines.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any

from django.contrib import admin
from django.db.models import Q
from nonrelated_inlines.admin import NonrelatedTabularInline
Expand Down Expand Up @@ -44,14 +46,14 @@ class PanoramaInline(BetterNonrelatedInline):
readonly_fields = fields
template = "admin/node_panorama_viewer.html"

all_panoramas = []
all_panoramas: dict[str, list[Any]] = {}

def get_form_queryset(self, obj):
buildings = self.model.objects.filter(nodes=obj)
self.all_panoramas = []
panoramas = []
for b in buildings:
self.all_panoramas += b.panoramas
self.all_panoramas = {"value": self.all_panoramas}
panoramas += b.panoramas
self.all_panoramas = {"value": panoramas}
return buildings

class Media:
Expand Down
4 changes: 2 additions & 2 deletions src/meshapi/docs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from textwrap import dedent
from typing import Dict, Optional
from typing import Dict, List, Optional

from django.urls import reverse
from drf_spectacular.authentication import SessionScheme
Expand Down Expand Up @@ -74,7 +74,7 @@ def get_security_definition(self, auto_schema):
)


def map_query_filters_to_param_annotations(query_filters: Dict[str, Optional[str]]):
def map_query_filters_to_param_annotations(query_filters: Dict[str, Optional[str]]) -> List[OpenApiParameter]:
param_annotations = []
for param_name, filter_strategy in query_filters.items():
filter_strategy_human_readable = {
Expand Down
3 changes: 2 additions & 1 deletion src/meshapi/management/commands/create_groups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from argparse import ArgumentParser
from typing import Any

from django.contrib.auth.models import Group, Permission
from django.core.management.base import BaseCommand
Expand All @@ -10,7 +11,7 @@ class Command(BaseCommand):
def add_arguments(self, parser: ArgumentParser) -> None:
pass

def handle(self, *args, **options) -> None:
def handle(self, *args: Any, **options: Any) -> None:
models = [
"building",
"member",
Expand Down
7 changes: 4 additions & 3 deletions src/meshapi/management/commands/scramble_members.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from argparse import ArgumentParser
from datetime import timedelta
from datetime import date, timedelta
from random import randint, randrange
from typing import Any, Tuple

from django.core.management.base import BaseCommand
from django.db import transaction
Expand Down Expand Up @@ -32,7 +33,7 @@ def add_arguments(self, parser: ArgumentParser) -> None:
)

@transaction.atomic
def handle(self, *args, **options):
def handle(self, *args: Any, **options: Any) -> None:
print("Scrambling database with fake information")
fake = Faker()
if not options["skip_members"]:
Expand Down Expand Up @@ -104,7 +105,7 @@ def handle(self, *args, **options):
print("Done")

@staticmethod
def fuzz_dates(request_date, install_date, abandon_date):
def fuzz_dates(request_date: date | None, install_date: date, abandon_date: date) -> Tuple[date | None, date, date]:
if request_date:
# Make it happen sooner so that there's no way the request date is
# now beyond the install/abandon date.
Expand Down
4 changes: 2 additions & 2 deletions src/meshapi/views/lookups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, List

from django.db.models import Q
from django_filters import rest_framework as filters
Expand Down Expand Up @@ -50,7 +50,7 @@ def filter_on_all_emails(self, queryset, name, value):

class Meta:
model = Member
fields = []
fields: List[Any] = []


@extend_schema_view(
Expand Down
2 changes: 1 addition & 1 deletion src/meshapi/views/panoramas.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def sync_github_panoramas() -> tuple[int, list[str]]:


def set_panoramas(panos: dict[str, list[str]]) -> tuple[int, list[str]]:
def build_panorama_list(building: Building, filenames: list[str]):
def build_panorama_list(building: Building, filenames: list[str]) -> None:
panoramas = []
for filename in filenames:
file_url = f"{host_url}{filename}"
Expand Down
4 changes: 3 additions & 1 deletion src/meshapi/views/query_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, List

from django.db.models import Q
from django_filters import rest_framework as filters
from drf_spectacular.utils import extend_schema, extend_schema_view
Expand Down Expand Up @@ -31,7 +33,7 @@ def filter_on_all_emails(self, queryset, name, value):

class Meta:
model = Install
fields = []
fields: List[Any] = []


@extend_schema_view(
Expand Down
Loading