From 4315225642631cb4cc606299b5e0a9e3a55bae52 Mon Sep 17 00:00:00 2001 From: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com> Date: Thu, 1 Jul 2021 17:43:59 +0200 Subject: [PATCH] Type Hinting Fixes (#2552) * Fixe overload signatures for ContextTypes * more fixing for contexttypes --- telegram/ext/contexttypes.py | 64 ++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/telegram/ext/contexttypes.py b/telegram/ext/contexttypes.py index 2156e7f62..badf7331a 100644 --- a/telegram/ext/contexttypes.py +++ b/telegram/ext/contexttypes.py @@ -50,9 +50,11 @@ class ContextTypes(Generic[CCT, UD, CD, BD]): __slots__ = ('_context', '_bot_data', '_chat_data', '_user_data') + # overload signatures generated with https://git.io/JtJPj + @overload def __init__( - self: 'ContextTypes[CallbackContext, Dict, Dict, Dict]', + self: 'ContextTypes[CallbackContext[Dict, Dict, Dict], Dict, Dict, Dict]', ): ... @@ -61,20 +63,26 @@ class ContextTypes(Generic[CCT, UD, CD, BD]): ... @overload - def __init__(self: 'ContextTypes[CallbackContext, UD, Dict, Dict]', bot_data: Type[UD]): - ... - - @overload - def __init__(self: 'ContextTypes[CallbackContext, Dict, CD, Dict]', chat_data: Type[CD]): - ... - - @overload - def __init__(self: 'ContextTypes[CallbackContext, Dict, Dict, BD]', user_data: Type[BD]): + def __init__( + self: 'ContextTypes[CallbackContext[UD, Dict, Dict], UD, Dict, Dict]', user_data: Type[UD] + ): ... @overload def __init__( - self: 'ContextTypes[CCT, UD, Dict, Dict]', context: Type[CCT], bot_data: Type[UD] + self: 'ContextTypes[CallbackContext[Dict, CD, Dict], Dict, CD, Dict]', chat_data: Type[CD] + ): + ... + + @overload + def __init__( + self: 'ContextTypes[CallbackContext[Dict, Dict, BD], Dict, Dict, BD]', bot_data: Type[BD] + ): + ... + + @overload + def __init__( + self: 'ContextTypes[CCT, UD, Dict, Dict]', context: Type[CCT], user_data: Type[UD] ): ... @@ -86,31 +94,31 @@ class ContextTypes(Generic[CCT, UD, CD, BD]): @overload def __init__( - self: 'ContextTypes[CCT, Dict, Dict, BD]', context: Type[CCT], user_data: Type[BD] + self: 'ContextTypes[CCT, Dict, Dict, BD]', context: Type[CCT], bot_data: Type[BD] ): ... @overload def __init__( - self: 'ContextTypes[CallbackContext, UD, CD, Dict]', - bot_data: Type[UD], + self: 'ContextTypes[CallbackContext[UD, CD, Dict], UD, CD, Dict]', + user_data: Type[UD], chat_data: Type[CD], ): ... @overload def __init__( - self: 'ContextTypes[CallbackContext, UD, Dict, BD]', - bot_data: Type[UD], - user_data: Type[BD], + self: 'ContextTypes[CallbackContext[UD, Dict, BD], UD, Dict, BD]', + user_data: Type[UD], + bot_data: Type[BD], ): ... @overload def __init__( - self: 'ContextTypes[CallbackContext, Dict, CD, BD]', + self: 'ContextTypes[CallbackContext[Dict, CD, BD], Dict, CD, BD]', chat_data: Type[CD], - user_data: Type[BD], + bot_data: Type[BD], ): ... @@ -118,7 +126,7 @@ class ContextTypes(Generic[CCT, UD, CD, BD]): def __init__( self: 'ContextTypes[CCT, UD, CD, Dict]', context: Type[CCT], - bot_data: Type[UD], + user_data: Type[UD], chat_data: Type[CD], ): ... @@ -127,8 +135,8 @@ class ContextTypes(Generic[CCT, UD, CD, BD]): def __init__( self: 'ContextTypes[CCT, UD, Dict, BD]', context: Type[CCT], - bot_data: Type[UD], - user_data: Type[BD], + user_data: Type[UD], + bot_data: Type[BD], ): ... @@ -137,16 +145,16 @@ class ContextTypes(Generic[CCT, UD, CD, BD]): self: 'ContextTypes[CCT, Dict, CD, BD]', context: Type[CCT], chat_data: Type[CD], - user_data: Type[BD], + bot_data: Type[BD], ): ... @overload def __init__( - self: 'ContextTypes[CallbackContext, UD, CD, BD]', - bot_data: Type[UD], + self: 'ContextTypes[CallbackContext[UD, CD, BD], UD, CD, BD]', + user_data: Type[UD], chat_data: Type[CD], - user_data: Type[BD], + bot_data: Type[BD], ): ... @@ -154,9 +162,9 @@ class ContextTypes(Generic[CCT, UD, CD, BD]): def __init__( self: 'ContextTypes[CCT, UD, CD, BD]', context: Type[CCT], - bot_data: Type[UD], + user_data: Type[UD], chat_data: Type[CD], - user_data: Type[BD], + bot_data: Type[BD], ): ...