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

Don't use typing import if possible #4134

Merged
merged 4 commits into from
Oct 23, 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
6 changes: 2 additions & 4 deletions backend/api/blog/schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List, Optional

from api.context import Info
import strawberry

Expand All @@ -12,7 +10,7 @@
@strawberry.type
class BlogQuery:
@strawberry.field
def blog_posts(self, info) -> List[PostType]:
def blog_posts(self, info) -> list[PostType]:
return [
PostType(
id=post.id,
Expand All @@ -34,7 +32,7 @@ def blog_posts(self, info) -> List[PostType]:
]

@strawberry.field
def blog_post(self, info: Info, slug: str) -> Optional[PostType]:
def blog_post(self, info: Info, slug: str) -> PostType | None:
post = Post.published_posts.by_slug(slug).first()

if not post:
Expand Down
4 changes: 1 addition & 3 deletions backend/api/checklist/query.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

import strawberry

from checklist.models import ChecklistItem as ChecklistItemModel
Expand All @@ -18,7 +16,7 @@ def from_django(cls, instance):
@strawberry.type
class ChecklistQuery:
@strawberry.field
def checklist(self) -> List[ChecklistItem]:
def checklist(self) -> list[ChecklistItem]:
return [
ChecklistItem.from_django(instance)
for instance in ChecklistItemModel.objects.all()
Expand Down
6 changes: 2 additions & 4 deletions backend/api/cms/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import typing

import strawberry
from strawberry import ID
from api.pages.types import Page
Expand All @@ -19,13 +17,13 @@ class MenuLink:
href: str = strawberry.field(resolver=make_localized_resolver("href"))
title: str = strawberry.field(resolver=make_localized_resolver("title"))
is_primary: bool
page: typing.Optional[Page]
page: Page | None


@strawberry.type
class Menu:
title: str = strawberry.field(resolver=make_localized_resolver("title"))

@strawberry.field
def links(self, info) -> typing.List[MenuLink]:
def links(self, info) -> list[MenuLink]:
return self.links.all()
4 changes: 2 additions & 2 deletions backend/api/conferences/helpers/days.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typing
from datetime import date, timedelta
from typing import Iterator


def daterange(start_date: date, end_date: date) -> typing.Iterator[date]:
def daterange(start_date: date, end_date: date) -> Iterator[date]:
for n in range(int((end_date - start_date).days)):
yield start_date + timedelta(days=n)
9 changes: 4 additions & 5 deletions backend/api/conferences/schema.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from api.context import Info
from api.conferences.types import Conference
import strawberry

from conferences.models import Conference

from . import types
from conferences.models import Conference as ConferenceModel


@strawberry.type
class ConferenceQuery:
@strawberry.field
def conference(self, info: Info, code: str) -> types.Conference:
return Conference.objects.prefetch_related("durations").get(code=code)
def conference(self, info: Info, code: str) -> Conference:
return ConferenceModel.objects.prefetch_related("durations").get(code=code)
108 changes: 52 additions & 56 deletions backend/api/conferences/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.db.models import Prefetch
from participants.models import Participant as ParticipantModel
from datetime import datetime
from typing import List, Optional
from api.participants.types import Participant
from api.schedule.types.day import Day

Expand Down Expand Up @@ -58,31 +57,45 @@ def from_django_model(cls, instance):
)


DeadlineStatusType = strawberry.enum(DeadlineStatus)


@strawberry.type
class Deadline:
id: strawberry.ID
type: str
name: str = strawberry.field(resolver=make_localized_resolver("name"))
description: str = strawberry.field(resolver=make_localized_resolver("description"))
start: datetime
end: datetime
status: DeadlineStatusType


@strawberry.type
class Keynote:
id: ID
title: str = strawberry.field(resolver=make_localized_resolver("title"))
description: str = strawberry.field(resolver=make_localized_resolver("description"))
slug: str = strawberry.field(resolver=make_localized_resolver("slug"))
topic: Optional[Topic]
speakers: List[ScheduleItemUser]
start: Optional[datetime]
end: Optional[datetime]
rooms: List[Room]
youtube_video_id: Optional[str]
topic: Topic | None
speakers: list[ScheduleItemUser] | None
start: datetime | None
end: datetime | None
rooms: list[Room]
youtube_video_id: str | None

def __init__(
self,
id: ID,
title: str,
description: str,
slug: str,
topic: Optional[Topic],
speakers: List[ScheduleItemUser],
start: Optional[datetime],
end: Optional[datetime],
rooms: List[Room],
youtube_video_id: Optional[str],
topic: Topic | None,
speakers: list[ScheduleItemUser] | None,
start: datetime | None,
end: datetime | None,
rooms: list[Room],
youtube_video_id: str | None,
):
self.id = id
self.title = title
Expand Down Expand Up @@ -144,12 +157,12 @@ class Conference:
code: str
start: datetime
end: datetime
map: Optional[Map] = strawberry.field(resolver=resolve_map)
map: Map | None = strawberry.field(resolver=resolve_map)

pretix_event_url: str

@strawberry.field
def voucher(self, info: Info, code: str) -> Optional[Voucher]:
def voucher(self, info: Info, code: str) -> Voucher | None:
return get_voucher(self, code)

@strawberry.field
Expand All @@ -159,17 +172,17 @@ def timezone(self, info: Info) -> str:
@strawberry.field
def tickets(
self, info: Info, language: str, show_unavailable_tickets: bool = False
) -> List[TicketItem]:
) -> list[TicketItem]:
return get_conference_tickets(
self, language=language, show_unavailable_tickets=show_unavailable_tickets
)

@strawberry.field
def hotel_rooms(self, info: Info) -> List[HotelRoom]:
def hotel_rooms(self, info: Info) -> list[HotelRoom]:
return self.hotel_rooms.all()

@strawberry.field
def deadlines(self, info: Info) -> List["Deadline"]:
def deadlines(self, info: Info) -> list[Deadline]:
return self.deadlines.order_by("start").all()

@strawberry.field(name="isCFPOpen")
Expand All @@ -185,35 +198,35 @@ def is_voting_closed(self, info: Info) -> bool:
return self.is_voting_closed

@strawberry.field
def deadline(self, info: Info, type: str) -> Optional["Deadline"]:
def deadline(self, info: Info, type: str) -> Deadline | None:
return self.deadlines.filter(type=type).first()

@strawberry.field
def audience_levels(self, info: Info) -> List[AudienceLevel]:
def audience_levels(self, info: Info) -> list[AudienceLevel]:
return self.audience_levels.all()

@strawberry.field
def topics(self, info: Info) -> List[Topic]:
def topics(self, info: Info) -> list[Topic]:
return self.topics.all()

@strawberry.field
def languages(self, info: Info) -> List[Language]:
def languages(self, info: Info) -> list[Language]:
return self.languages.all()

@strawberry.field
def durations(self, info: Info) -> List["Duration"]:
def durations(self, info: Info) -> list["Duration"]:
return self.durations.all()

@strawberry.field
def submission_types(self, info: Info) -> List[SubmissionType]:
def submission_types(self, info: Info) -> list[SubmissionType]:
return self.submission_types.all()

@strawberry.field
def proposal_tags(self, info: Info) -> List[SubmissionTag]:
def proposal_tags(self, info: Info) -> list[SubmissionTag]:
return self.proposal_tags.all()

@strawberry.field(permission_classes=[CanSeeSubmissions])
def submissions(self, info: Info) -> Optional[List[Submission]]:
def submissions(self, info: Info) -> list[Submission] | None:
return self.submissions.filter(
status__in=(
SubmissionModel.STATUS.proposed,
Expand All @@ -222,56 +235,54 @@ def submissions(self, info: Info) -> Optional[List[Submission]]:
).select_related("audience_level", "duration", "type", "topic")

@strawberry.field
def events(self, info: Info) -> List[Event]:
def events(self, info: Info) -> list[Event]:
return self.events.all()

@strawberry.field
def faqs(self, info: Info) -> List[FAQ]:
def faqs(self, info: Info) -> list[FAQ]:
return self.faqs.all()

@strawberry.field
def sponsors_by_level(self, info: Info) -> List[SponsorsByLevel]:
def sponsors_by_level(self, info: Info) -> list[SponsorsByLevel]:
levels = self.sponsor_levels.all().order_by("order")

return [SponsorsByLevel.from_model(level) for level in levels]

@strawberry.field
def copy(
self, info: Info, key: str, language: Optional[str] = None
) -> Optional[str]:
def copy(self, info: Info, key: str, language: str | None = None) -> str | None:
copy = GenericCopy.objects.filter(conference=self, key=key).first()

language = language or translation.get_language() or settings.LANGUAGE_CODE

return copy.content.localize(language) if copy else None

@strawberry.field
def menu(self, info: Info, identifier: str) -> Optional[Menu]:
def menu(self, info: Info, identifier: str) -> Menu | None:
return (
self.menus.filter(identifier=identifier).prefetch_related("links").first()
)

@strawberry.field
def keynotes(self, info: Info) -> List[Keynote]:
def keynotes(self, info: Info) -> list[Keynote]:
return [
Keynote.from_django_model(keynote, info) for keynote in self.keynotes.all()
]

@strawberry.field
def keynote(self, info: Info, slug: str) -> Optional[Keynote]:
def keynote(self, info: Info, slug: str) -> Keynote | None:
keynote = self.keynotes.by_slug(slug).first()
return Keynote.from_django_model(keynote, info) if keynote else None

@strawberry.field
def talks(self, info: Info) -> List[ScheduleItem]:
def talks(self, info: Info) -> list[ScheduleItem]:
return self.schedule_items.filter(type=ScheduleItemModel.TYPES.submission).all()

@strawberry.field
def talk(self, info: Info, slug: str) -> Optional[ScheduleItem]:
def talk(self, info: Info, slug: str) -> ScheduleItem | None:
return self.schedule_items.filter(slug=slug).first()

@strawberry.field
def ranking(self, info: Info, topic: strawberry.ID) -> Optional[RankRequest]:
def ranking(self, info: Info, topic: strawberry.ID) -> RankRequest | None:
rank_request = RankRequestModel.objects.filter(conference=self).first()
if not rank_request:
return None
Expand All @@ -291,7 +302,7 @@ def ranking(self, info: Info, topic: strawberry.ID) -> Optional[RankRequest]:
)

@strawberry.field
def days(self, info: Info) -> List[Day]:
def days(self, info: Info) -> list[Day]:
days = list(
self.days.order_by("day")
.prefetch_related(
Expand Down Expand Up @@ -360,7 +371,7 @@ def days(self, info: Info) -> List[Day]:
return days

@strawberry.field
def current_day(self, info: Info) -> Optional[Day]:
def current_day(self, info: Info) -> Day | None:
start = timezone.now().replace(hour=0, minute=0, second=0)
end = start.replace(hour=23, minute=59, second=59)
return self.days.filter(day__gte=start, day__lte=end).first()
Expand Down Expand Up @@ -422,21 +433,6 @@ def sponsor_special_options(self) -> list[SponsorSpecialOption]:
]


DeadlineStatusType = strawberry.enum(DeadlineStatus)


@strawberry.type
class Deadline:
id: strawberry.ID
type: str
name: str = strawberry.field(resolver=make_localized_resolver("name"))
description: str = strawberry.field(resolver=make_localized_resolver("description"))
start: datetime
end: datetime
conference: Conference
status: DeadlineStatusType


@strawberry.type
class Duration:
id: strawberry.ID
Expand All @@ -446,5 +442,5 @@ class Duration:
notes: str

@strawberry.field
def allowed_submission_types(self, info: Info) -> List[SubmissionType]:
def allowed_submission_types(self, info: Info) -> list[SubmissionType]:
return self.allowed_submission_types.all()
4 changes: 1 addition & 3 deletions backend/api/countries/schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

from api.context import Info
import strawberry

Expand All @@ -10,7 +8,7 @@
@strawberry.type
class CountryQuery:
@strawberry.field
def countries(self, info: Info) -> List[Country]:
def countries(self, info: Info) -> list[Country]:
return [Country(code=country.code, name=country.name) for country in countries]

@strawberry.field
Expand Down
7 changes: 3 additions & 4 deletions backend/api/hotels/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import timedelta
from typing import List

import strawberry

Expand All @@ -22,11 +21,11 @@ class HotelRoom:
capacity_left: int

@strawberry.field
def available_bed_layouts(self) -> List[BedLayout]:
def available_bed_layouts(self) -> list[BedLayout]:
return self.available_bed_layouts.all()

@strawberry.field
def check_in_dates(self) -> List[str]:
def check_in_dates(self) -> list[str]:
conference_start = self.conference.start
conference_end = self.conference.end

Expand All @@ -36,7 +35,7 @@ def check_in_dates(self) -> List[str]:
]

@strawberry.field
def check_out_dates(self) -> List[str]:
def check_out_dates(self) -> list[str]:
conference_start = self.conference.start
conference_end = self.conference.end

Expand Down
Loading