Skip to content

Commit

Permalink
some fixes & improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
luwqz1 committed Jun 20, 2024
1 parent 4b00ebd commit 694289f
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 24 deletions.
2 changes: 1 addition & 1 deletion telegrinder/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DataConverter:
def __repr__(self) -> str:
return "<{}: {}>".format(
self.__class__.__name__,
", ".join(f"{k}={v!r}" for k, v in self.converters),
", ".join(f"{k}={v.__name__!r}" for k, v in self.converters.items()),
)

@property
Expand Down
14 changes: 7 additions & 7 deletions telegrinder/types/objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typing

from fntypes.co import Some, Variative
from fntypes.co import Variative

from telegrinder.model import Model
from telegrinder.msgspec_utils import Nothing, Option, datetime
Expand Down Expand Up @@ -5518,7 +5518,7 @@ class RevenueWithdrawalStatePending(RevenueWithdrawalState):
The withdrawal is in progress.
"""

type: str
type: typing.Literal["pending"]
"""Type of the state, always `pending`."""


Expand All @@ -5528,7 +5528,7 @@ class RevenueWithdrawalStateSucceeded(RevenueWithdrawalState):
The withdrawal succeeded.
"""

type: str
type: typing.Literal["succeeded"]
"""Type of the state, always `succeeded`."""

date: datetime
Expand All @@ -5544,7 +5544,7 @@ class RevenueWithdrawalStateFailed(RevenueWithdrawalState):
The withdrawal failed and the transaction was refunded.
"""

type: str
type: typing.Literal["failed"]
"""Type of the state, always `failed`."""


Expand All @@ -5554,7 +5554,7 @@ class TransactionPartnerFragment(TransactionPartner):
Describes a withdrawal transaction with Fragment.
"""

type: str
type: typing.Literal["fragment"]
"""Type of the transaction partner, always `fragment`."""

withdrawal_state: Option[
Expand All @@ -5571,7 +5571,7 @@ class TransactionPartnerUser(TransactionPartner):
Describes a transaction with a user.
"""

type: str
type: typing.Literal["user"]
"""Type of the transaction partner, always `user`."""

user: "User"
Expand All @@ -5584,7 +5584,7 @@ class TransactionPartnerOther(TransactionPartner):
Describes a transaction with an unknown source or recipient.
"""

type: str
type: typing.Literal["other"]
"""Type of the transaction partner, always `other`."""


Expand Down
66 changes: 66 additions & 0 deletions typegen/config_literal_types.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,72 @@
}
]
},
{
"name": "RevenueWithdrawalStatePending",
"fields": [
{
"name": "type",
"literals": [
"pending"
]
}
]
},
{
"name": "RevenueWithdrawalStateSucceeded",
"fields": [
{
"name": "type",
"literals": [
"succeeded"
]
}
]
},
{
"name": "RevenueWithdrawalStateFailed",
"fields": [
{
"name": "type",
"literals": [
"failed"
]
}
]
},
{
"name": "TransactionPartnerFragment",
"fields": [
{
"name": "type",
"literals": [
"fragment"
]
}
]
},
{
"name": "TransactionPartnerUser",
"fields": [
{
"name": "type",
"literals": [
"user"
]
}
]
},
{
"name": "TransactionPartnerOther",
"fields": [
{
"name": "type",
"literals": [
"other"
]
}
]
},
{
"name": "EncryptedPassportElement",
"fields": [
Expand Down
26 changes: 10 additions & 16 deletions typegen/nicifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,20 @@ def full_name(self) -> str:

class _Update(Update):
def __eq__(self, other: typing.Any) -> bool:
return (
isinstance(other, self.__class__)
and self.update_type.map(
lambda x: x == other.update_type.unwrap_or_none(),
).unwrap_or(False)
)
return isinstance(other, self.__class__) and self.update_type == other.update_type

@property
def update_type(self) -> Option[UpdateType]:
def update_type(self) -> UpdateType:
"""Incoming update type."""

if update := next(
filter(
lambda x: bool(x[1]),
self.to_dict(exclude_fields={"update_id"}).items(),
),
None,
):
return Some(UpdateType(update[0]))
return Nothing
return UpdateType(
next(
filter(
lambda x: bool(x[1]),
self.to_dict(exclude_fields={"update_id"}).items(),
),
)[0],
)


class _InputFile(typing.NamedTuple):
Expand Down

0 comments on commit 694289f

Please sign in to comment.