From f4d137b6f091ffb304adccbc30d6ee3ae745ecaf Mon Sep 17 00:00:00 2001 From: Alexander Loechel Date: Tue, 23 Apr 2024 02:13:15 +0200 Subject: [PATCH] fix mypy issues with __call_ order on multiple inheritance --- src/edutap/wallet_google/api.py | 6 +-- src/edutap/wallet_google/modelbase.py | 10 ++-- src/edutap/wallet_google/modelcore.py | 12 ++++- src/edutap/wallet_google/models/issuer.py | 4 +- src/edutap/wallet_google/models/jwt.py | 2 +- .../models/primitives/datetime.py | 20 ++----- .../models/primitives/location.py | 19 +++---- .../models/primitives/message.py | 11 +++- .../models/tickets_and_transit.py | 52 +++++++++++++++++-- src/edutap/wallet_google/registry.py | 2 +- 10 files changed, 89 insertions(+), 49 deletions(-) diff --git a/src/edutap/wallet_google/api.py b/src/edutap/wallet_google/api.py index 9807802..4150e03 100644 --- a/src/edutap/wallet_google/api.py +++ b/src/edutap/wallet_google/api.py @@ -1,9 +1,9 @@ -from .modelbase import GoogleWalletModel from .modelbase import GoogleWalletObjectWithClassReference +from .modelcore import GoogleWalletModel from .models.primitives import Pagination from .models.primitives.enums import State -from .models.primitives.notification import AddMessageRequest -from .models.primitives.notification import Message +from .models.primitives.message import AddMessageRequest +from .models.primitives.message import Message from .registry import lookup_metadata from .registry import lookup_model from .registry import lookup_model_by_plural_name diff --git a/src/edutap/wallet_google/modelbase.py b/src/edutap/wallet_google/modelbase.py index 06379f4..3d0939b 100644 --- a/src/edutap/wallet_google/modelbase.py +++ b/src/edutap/wallet_google/modelbase.py @@ -1,4 +1,3 @@ -from .modelcore import GoogleWalletModel from .modelcore import GoogleWalletWithIdModel from .models.primitives import CallbackOptions from .models.primitives import GroupingInfo @@ -14,7 +13,8 @@ from .models.primitives.data import TextModuleData from .models.primitives.enums import MultipleDevicesAndHoldersAllowedStatus from .models.primitives.enums import ViewUnlockRequirement -from .models.primitives.notification import Message +from .models.primitives.message import Message +from pydantic import BaseModel from pydantic import Field @@ -120,7 +120,7 @@ class GoogleWalletObjectModel(GoogleWalletWithIdModel): rotatingBarcode: RotatingBarcode | None = None -class GoogleWalletObjectWithClassReference(GoogleWalletObjectModel): +class GoogleWalletObjectWithClassReference(BaseModel): """ Model for all Google Wallet Object with a Class references. """ @@ -128,7 +128,7 @@ class GoogleWalletObjectWithClassReference(GoogleWalletObjectModel): classReference: GoogleWalletClassModel | None = None -class GoogleWalletMessageable(GoogleWalletModel): +class GoogleWalletMessageable: """ Model for Google Wallet Classes or Objects that can retrieve Messages """ @@ -136,7 +136,7 @@ class GoogleWalletMessageable(GoogleWalletModel): messages: list[Message] | None = None -class GoogleWalletStyleable(GoogleWalletModel): +class GoogleWalletStyleable: """ Model for Google Wallet Classes or Objects that can be styled """ diff --git a/src/edutap/wallet_google/modelcore.py b/src/edutap/wallet_google/modelcore.py index 45dc4d3..df7972a 100644 --- a/src/edutap/wallet_google/modelcore.py +++ b/src/edutap/wallet_google/modelcore.py @@ -15,10 +15,18 @@ class GoogleWalletModel(BaseModel): ) -class GoogleWalletWithIdModel(GoogleWalletModel): +class GoogleWalletWithKindModel(GoogleWalletModel): """ - Base model for Google Wallet models with an identifier. + Base model for Google Wallet models with an deprecated kind identifier. """ kind: str | None = Field(description="deprecated", exclude=True, default=None) + + +class GoogleWalletWithIdModel(GoogleWalletWithKindModel): + """ + Base model for Google Wallet models with an identifier. + """ + + # kind: str | None = Field(description="deprecated", exclude=True, default=None) id: str diff --git a/src/edutap/wallet_google/models/issuer.py b/src/edutap/wallet_google/models/issuer.py index 59cd3f6..dcf0107 100644 --- a/src/edutap/wallet_google/models/issuer.py +++ b/src/edutap/wallet_google/models/issuer.py @@ -1,5 +1,5 @@ -from ..modelbase import GoogleWalletModel -from ..modelbase import GoogleWalletWithIdModel +from ..modelcore import GoogleWalletModel +from ..modelcore import GoogleWalletWithIdModel from ..registry import register_model from .primitives.smarttap import IssuerContactInfo from .primitives.smarttap import IssuerToUserInfo diff --git a/src/edutap/wallet_google/models/jwt.py b/src/edutap/wallet_google/models/jwt.py index 7bb97c9..1a7c268 100644 --- a/src/edutap/wallet_google/models/jwt.py +++ b/src/edutap/wallet_google/models/jwt.py @@ -1,6 +1,6 @@ from ..modelbase import GoogleWalletClassModel -from ..modelbase import GoogleWalletModel from ..modelbase import GoogleWalletObjectModel +from ..modelcore import GoogleWalletModel from ..registry import register_model # from . import generic diff --git a/src/edutap/wallet_google/models/primitives/datetime.py b/src/edutap/wallet_google/models/primitives/datetime.py index 0f63ed3..f4b1ecd 100644 --- a/src/edutap/wallet_google/models/primitives/datetime.py +++ b/src/edutap/wallet_google/models/primitives/datetime.py @@ -1,11 +1,9 @@ -from .enums import DoorsOpenLabel -from .localized_string import LocalizedString -from pydantic import BaseModel +from ...modelcore import GoogleWalletModel import datetime -class DateTime(BaseModel): +class DateTime(GoogleWalletModel): """ see: https://developers.google.com/wallet/tickets/events/rest/v1/DateTime """ @@ -13,19 +11,7 @@ class DateTime(BaseModel): date: datetime.datetime -class EventDateTime(BaseModel): - """ - see: https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass#eventdatetime - """ - - doorsOpen: datetime.datetime | None = None - start: datetime.datetime | None = None - end: datetime.datetime | None = None - doorsOpenLabel: DoorsOpenLabel | None = None - customDoorsOpenLabel: LocalizedString | None = None - - -class TimeInterval(BaseModel): +class TimeInterval(GoogleWalletModel): """ see: https://developers.google.com/wallet/tickets/events/rest/v1/TimeInterval """ diff --git a/src/edutap/wallet_google/models/primitives/location.py b/src/edutap/wallet_google/models/primitives/location.py index ec05662..bc9115f 100644 --- a/src/edutap/wallet_google/models/primitives/location.py +++ b/src/edutap/wallet_google/models/primitives/location.py @@ -1,21 +1,16 @@ -from .localized_string import LocalizedString -from pydantic import BaseModel +from ...modelcore import GoogleWalletWithKindModel from pydantic import Field -class LatLongPoint(BaseModel): +class LatLongPoint(GoogleWalletWithKindModel): """ see: https://developers.google.com/wallet/retail/loyalty-cards/rest/v1/LatLongPoint """ + kind: str | None = Field( + description="deprecated", + exclude=True, + default="walletobjects#latLongPoint", + ) latitude: float = Field(ge=-90.0, le=90.0) longitude: float = Field(ge=-180.0, le=180.0) - - -class EventVenue(BaseModel): - """ - see: https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass#eventvenue - """ - - name: LocalizedString | None = None - address: LocalizedString | None = None diff --git a/src/edutap/wallet_google/models/primitives/message.py b/src/edutap/wallet_google/models/primitives/message.py index 3bf4b66..0c288b3 100644 --- a/src/edutap/wallet_google/models/primitives/message.py +++ b/src/edutap/wallet_google/models/primitives/message.py @@ -3,14 +3,21 @@ from .datetime import TimeInterval from .enums import MessageType from .localized_string import LocalizedString +from pydantic import Field -class Message(GoogleWalletModel, GoogleWalletWithIdModel): +class Message( + GoogleWalletWithIdModel, +): """ see: https://developers.google.com/wallet/tickets/events/rest/v1/Message """ - # id: str | None = None + kind: str | None = Field( + description="deprecated", + exclude=True, + default="walletobjects#walletObjectMessage", + ) messageType: MessageType = MessageType.MESSAGE_TYPE_UNSPECIFIED displayInterval: TimeInterval | None = None header: str | None = None diff --git a/src/edutap/wallet_google/models/tickets_and_transit.py b/src/edutap/wallet_google/models/tickets_and_transit.py index 55296f7..66df63e 100644 --- a/src/edutap/wallet_google/models/tickets_and_transit.py +++ b/src/edutap/wallet_google/models/tickets_and_transit.py @@ -3,12 +3,13 @@ from ..modelbase import GoogleWalletObjectModel from ..modelbase import GoogleWalletObjectWithClassReference from ..modelbase import GoogleWalletStyleable +from ..modelcore import GoogleWalletWithKindModel from ..registry import register_model from .primitives import Uri from .primitives.data import AppLinkData -from .primitives.datetime import EventDateTime from .primitives.datetime import TimeInterval from .primitives.enums import ConfirmationCodeLabel +from .primitives.enums import DoorsOpenLabel from .primitives.enums import GateLabel from .primitives.enums import ReviewStatus from .primitives.enums import RowLabel @@ -16,13 +17,45 @@ from .primitives.enums import SectionLabel from .primitives.enums import State from .primitives.localized_string import LocalizedString -from .primitives.location import EventVenue from .primitives.location import LatLongPoint from .primitives.money import Money from .primitives.review import Review from pydantic import BaseModel from pydantic import Field +import datetime + + +class EventVenue(GoogleWalletWithKindModel): + """ + see: https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass#eventvenue + """ + + kind: str | None = Field( + description="deprecated", + exclude=True, + default="walletobjects#eventDateTime", + ) + name: LocalizedString | None = None + address: LocalizedString | None = None + + +class EventDateTime(GoogleWalletWithKindModel): + """ + see: https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass#eventdatetime + """ + + kind: str | None = Field( + description="deprecated", + exclude=True, + default="walletobjects#eventDateTime", + ) + doorsOpen: datetime.datetime | None = None + start: datetime.datetime | None = None + end: datetime.datetime | None = None + doorsOpenLabel: DoorsOpenLabel | None = None + customDoorsOpenLabel: LocalizedString | None = None + @register_model( "EventTicketClass", @@ -31,8 +64,17 @@ can_disable=False, ) class EventTicketClass(GoogleWalletClassModel, GoogleWalletMessageable): + """ + see: https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass + """ + + kind: str | None = Field( + description="deprecated", + exclude=True, + default="walletobjects#eventTicketClass", + ) eventName: LocalizedString | None = None - eventId: str | None = None + eventId: str | None = Field(default=None, max_length=64) venue: EventVenue | None = None dateTime: EventDateTime | None = None confirmationCodeLabel: ConfirmationCodeLabel | None = None @@ -68,7 +110,9 @@ class EventReservationInfo(BaseModel): @register_model( - "EventTicketObject", url_part="eventTicketObject", plural="eventTicketObjects" + "EventTicketObject", + url_part="eventTicketObject", + plural="eventTicketObjects", ) class EventTicketObject( GoogleWalletObjectModel, diff --git a/src/edutap/wallet_google/registry.py b/src/edutap/wallet_google/registry.py index ee63842..085a61c 100644 --- a/src/edutap/wallet_google/registry.py +++ b/src/edutap/wallet_google/registry.py @@ -1,4 +1,4 @@ -from .modelbase import GoogleWalletModel +from .modelcore import GoogleWalletModel from typing import TypedDict