-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Closed
🐛 bug
Copy link
Description
Steps to Reproduce
pip install python-telegram-bot nuitka- Create minimal python file
main.py(The actual content does not matter as long astelegramis imported and used)
from telegram.ext import ApplicationBuilder
app = ApplicationBuilder()- Run
main.py. Note that deprecation warning is not appearing (Which is correct behaviour) - Compile with nuitka by
python -m nuitka --standalone main.py - Run the compiled program. Note that deprecation warning is appearing incorrectly, even though
python-telegram-botis installed instead ofpython-telegram-bot-raw
PTBUserWarning: Hey. You seem to be using the `python-telegram-bot-raw` library. Please note that this libray has been deprecated and will no longer be updated. Please instead use the `python-telegram-bot` library. The change requires no changes in your code and requires no additional dependencies. For additional information, please see the channel post at https://t.me/pythontelegrambotchannel/145
Expected behaviour
Deprecation warning should not appear when compiled with Nuitka
Actual behaviour
Deprecation warning appears when compiled with Nuitka even if python-telegram-bot is used instead of python-telegram-bot-raw
Operating System
Any (Recommend to test on Linux)
Version of Python, python-telegram-bot & dependencies
python-telegram-bot 21.3
Bot API 7.4
Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)]Relevant log output
No response
Additional Context
Related issue: #4261
Related PR: #4270
Related code:
python-telegram-bot/telegram/__init__.py
Lines 482 to 504 in a9f6afd
| if not (Path(__file__).parent.resolve().absolute() / "ext").exists(): | |
| _MESSAGE = ( | |
| "Hey. You seem to be using the `python-telegram-bot-raw` library. " | |
| "Please note that this libray has been deprecated and will no longer be updated. " | |
| "Please instead use the `python-telegram-bot` library. The change requires no " | |
| "changes in your code and requires no additional dependencies. For additional " | |
| "information, please see the channel post at " | |
| "https://t.me/pythontelegrambotchannel/145." | |
| ) | |
| # DeprecationWarning is ignored by default in Python 3.7 and later by default outside | |
| # __main__ modules. We use both warning categories to increase the chance of the user | |
| # seeing the warning. | |
| warn( | |
| warnings.PTBDeprecationWarning(version="21.3", message=_MESSAGE), | |
| stacklevel=2, | |
| ) | |
| warn( | |
| message=_MESSAGE, | |
| category=warnings.PTBUserWarning, | |
| stacklevel=2, | |
| ) |
This is happening because main.dist/telegram/ext is missing in the Nuitka compilation result.
Instead of checking by if not (Path(__file__).parent.resolve().absolute() / "ext").exists():, I propose using this check instead:
import importlib.utils
if importlib.util.find_spec("telegram.ext") is None:
...houshmand-2005
Metadata
Metadata
Assignees
Labels
No labels