Update callback_data.py

Allows using a default value in the class which is equal to an empty string ("").

Example:
class MyCallbackData(CallbackData, prefix="MyCallbackData"):
    input1: str
    input2: str = ""
This commit is contained in:
m-xim 2024-05-26 04:18:33 +03:00 committed by GitHub
parent 895f4f8dce
commit 2ba67ab04a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -131,7 +131,7 @@ class CallbackData(BaseModel):
for k, v in zip(names, parts): # type: str, Optional[str]
if field := cls.model_fields.get(k):
if v == "" and _check_field_is_nullable(field):
v = None
v = field.default
payload[k] = v
return cls(**payload)