From 22d9077e2bb11e350d9a408aedbe29b60e9c0373 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 29 Aug 2020 15:12:45 +0200 Subject: [PATCH] Warn users in case they try to use base types as arguments --- compiler/api/compiler.py | 3 ++- compiler/api/template/type.txt | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index e956085f..6c3dcb27 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -336,7 +336,8 @@ def start(format: bool = False): docstring=docstring, name=type, qualname=qualtype, - types=", ".join([f"raw.types.{c}" for c in constructors]) + types=", ".join([f"raw.types.{c}" for c in constructors]), + doc_name=snake(type).replace("_", "-") ) ) diff --git a/compiler/api/template/type.txt b/compiler/api/template/type.txt index 3d327282..99310359 100644 --- a/compiler/api/template/type.txt +++ b/compiler/api/template/type.txt @@ -15,3 +15,9 @@ class {name}: # type: ignore """ QUALNAME = "pyrogram.raw.base.{qualname}" + + def __init__(self): + raise TypeError("Base types can only be used for type checking purposes: " + "you tried to use a base type instance as argument, " + "but you need to instantiate one of its constructors instead. " + "More info: https://docs.pyrogram.org/telegram/base/{doc_name}")