From b377564f55055d5fb08813b4aeeb3855d9fc24dd Mon Sep 17 00:00:00 2001 From: andrew000 <11490628+andrew000@users.noreply.github.com> Date: Mon, 20 Jun 2022 23:21:22 +0300 Subject: [PATCH] Rework warning for not defined fields --- aiogram/types/base.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aiogram/types/base.py b/aiogram/types/base.py index cca3d5f1..b5befd38 100644 --- a/aiogram/types/base.py +++ b/aiogram/types/base.py @@ -3,12 +3,14 @@ from __future__ import annotations import io import logging import typing +import warnings from typing import TypeVar from babel.support import LazyProxy from .fields import BaseField from ..utils import json +from ..utils.exceptions import AIOGramWarning from ..utils.mixins import ContextInstanceMixin if typing.TYPE_CHECKING: from ..bot.bot import Bot @@ -243,8 +245,10 @@ class TelegramObject(ContextInstanceMixin, metaclass=MetaTelegramObject): return self.props[key].set_value(self, value, self.conf.get('parent', self)) self.values[key] = value - # Log warning when Telegram silently adds new Fields - log.warning("Field '%s' doesn't exist in %s", key, self.__class__) + # Show warning when Telegram silently adds new Fields + warnings.warn(f"Bot API Field {key!r} is not defined in {self.__class__!r} class.\n" + "Bot API has been updated. Check for updates at https://telegram.org/blog and " + "https://github.com/aiogram/aiogram/releases", AIOGramWarning) def __contains__(self, item: str) -> bool: """