Fix compatibility with pydantic 1.5 (temporary)

This commit is contained in:
Alex Root Junior 2020-04-28 12:07:01 +03:00
parent 01c6303d67
commit e9fef19129
5 changed files with 117 additions and 77 deletions

View file

@ -20,10 +20,14 @@ class CallableMixin:
spec: inspect.FullArgSpec = field(init=False)
def __post_init__(self) -> None:
callback = self.callback
callback = inspect.unwrap(self.callback)
self.awaitable = inspect.isawaitable(callback) or inspect.iscoroutinefunction(callback)
while hasattr(callback, "__wrapped__"): # Try to resolve decorated callbacks
callback = callback.__wrapped__ # type: ignore
if isinstance(callback, BaseFilter):
# Pydantic 1.5 has incorrect signature generator
# Issue: https://github.com/samuelcolvin/pydantic/issues/1419
# Fixes: https://github.com/samuelcolvin/pydantic/pull/1427
# TODO: Remove this temporary fix
callback = inspect.unwrap(callback.__call__)
self.spec = inspect.getfullargspec(callback)
def _prepare_kwargs(self, kwargs: Dict[str, Any]) -> Dict[str, Any]:

View file

@ -30,7 +30,7 @@ class BaseHandler(BaseHandlerMixin[T], ABC):
@property
def update(self) -> Update:
return cast(Update, self.data["update"])
return cast(Update, self.data.get("update", self.data.get("event_update")))
@abstractmethod
async def handle(self) -> Any: # pragma: no cover