-
Notifications
You must be signed in to change notification settings - Fork 0
Type Checking
Since Python 3.6, static type hinting is established in Python and PTB makes use of it (since v13.0). Static type checking helps to avoid and find errors both in PTBs source code and in your bot code. If you want to take advantage of this, you should use a type checker to check your code. As type checking in general is not PTB specific and a big topic, an introduction to type hinting is beyond the scope of this wiki.
While static type hints are of great value and we try our best to make them as precise as possible, they usually don't have any implications on runtime behavior. It therefore may happen that some type hints are not perfect or outright wrong and we may change & fix them between minor versions without announcement. This may lead to your type checker reporting errors after an upgrade, but it won't introduce bugs into your code.
Please also note that type hinting in Python does not cover all edge cases, so there might be situations where PTB just can't do better.
Of course, you are always welcome to report any type hinting errors through the bug tracker.
Some of the classes in telegram.ext
that may be subclassed by users are generic classes, i.e. subclasses of typing.Generic
.
When subclassing them, the type variables should be specified.
These classes currently are telegram.ext.Handler
, telegram.ext.BasePersistence
and telegram.ext.CallbackContext
.
Please have a look at the respective documentation page for more info on the type variables that these classes accept.
- Wiki of
python-telegram-bot
© Copyright 2015-2025 – Licensed by Creative Commons
- Architecture Overview
- Builder Pattern for
Application
- Types of Handlers
- Working with Files and Media
- Exceptions, Warnings and Logging
- Concurrency in PTB
- Advanced Filters
- Storing data
- Making your bot persistent
- Adding Defaults
- Job Queue
- Arbitrary
callback_data
- Avoiding flood limits
- Webhooks
- Bot API Forward Compatiblity
- Frequently requested design patterns
- Code snippets
- Performance Optimizations
- Telegram Passport
- Bots built with PTB
- Automated Bot Tests