Skip to content

[BUG] python-telegram-bot-raw deprecation warning appears incorrectly if compiled with Nuitka #4296

@laggykiller

Description

@laggykiller

Steps to Reproduce

  1. pip install python-telegram-bot nuitka
  2. Create minimal python file main.py (The actual content does not matter as long as telegram is imported and used)
from telegram.ext import ApplicationBuilder

app = ApplicationBuilder()
  1. Run main.py. Note that deprecation warning is not appearing (Which is correct behaviour)
  2. Compile with nuitka by python -m nuitka --standalone main.py
  3. Run the compiled program. Note that deprecation warning is appearing incorrectly, even though python-telegram-bot is installed instead of python-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:

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:
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy