Skip to content

Fix: Add fallback name support for job callbacks without __name__ #5088

Merged
Bibo-Joshi merged 4 commits intopython-telegram-bot:masterfrom
SmartDever02:fix/4992-callback-name-fallback
Jan 7, 2026
Merged

Fix: Add fallback name support for job callbacks without __name__ #5088
Bibo-Joshi merged 4 commits intopython-telegram-bot:masterfrom
SmartDever02:fix/4992-callback-name-fallback

Conversation

@SmartDever02
Copy link
Contributor

@SmartDever02 SmartDever02 commented Jan 7, 2026

attribute

  • Add _get_callback_name() helper function to handle callable class instances
  • Replace all callback.name accesses with _get_callback_name() calls
  • Add test to verify callable class instances work as job callbacks
  • Fixes AttributeError when using callable class instances as callbacks

Closes #4992

Check-list for PRs

  • Added .. versionadded:: NEXT.VERSION, .. versionchanged:: NEXT.VERSION, .. deprecated:: NEXT.VERSION or ``.. versionremoved:: NEXT.VERSION` to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)
  • Created new or adapted existing unit tests
  • Documented code changes according to the CSI standard
  • Added myself alphabetically to AUTHORS.rst (optional)
  • Added new classes & modules to the docs and all suitable __all__ s
  • Checked the Stability Policy in case of deprecations or changes to documented behavior

If the PR contains API changes (otherwise, you can ignore this passage)

  • Checked the Bot API specific sections of the Stability Policy

  • Created a PR to remove functionality deprecated in the previous Bot API release (see here)

  • New Classes

    • Added self._id_attrs and corresponding documentation
    • __init__ accepts api_kwargs as keyword-only
  • Added New Shortcuts

    • In telegram.Chat & telegram.User for all methods that accept chat/user_id
    • In telegram.Message for all methods that accept chat_id and message_id
    • For new telegram.Message shortcuts: Added quote argument if methods accept reply_to_message_id
    • In telegram.CallbackQuery for all methods that accept either chat_id and message_id or inline_message_id
  • If Relevant

    • Added new constants at telegram.constants and shortcuts to them as class variables
    • Linked new and existing constants in docstrings instead of hard-coded numbers and strings
    • Added new message types to telegram.Message.effective_attachment
    • Added new handlers for new update types
    • Added new filters for new message (sub)types
    • Added or updated documentation for the changed class(es) and/or method(s)
    • Added the new method(s) to _extbot.py
    • Added or updated bot_methods.rst
    • Updated the Bot API version number in all places: README.rst (including the badge) and telegram.constants.BOT_API_VERSION_INFO
    • Added logic for arbitrary callback data in telegram.ext.ExtBot for new methods that either accept a reply_markup in some form or have a return type that is/contains telegram.Message

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=102175066

…ribute

- Add _get_callback_name() helper function to handle callable class instances
- Replace all callback.__name__ accesses with _get_callback_name() calls
- Add test to verify callable class instances work as job callbacks
- Fixes AttributeError when using callable class instances as callbacks

Closes python-telegram-bot#4992
- Remove trailing whitespace from docstring
- Move ContextTypes import to top-level
- Fix line length issues
- Apply ruff formatting fixes
@SmartDever02
Copy link
Contributor Author

hello @Bibo-Joshi can you please check this pr?
btw plz let me know if I have to change the target branch.
thanks

Copy link
Member

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks very much for your PR!
Code looks good :) Please just add a new changelog frament at

changes/unreleased/5088.dbco4MBy5FHuS4qawHww3M.toml

with the content

features = "Add Fallback Name Support for Job Callbacks without ``__name__``"
[[pull_requests]]
uid = "5088"
author_uids = ["SmartDever02"]
closes_threads = ["4992"]

@SmartDever02
Copy link
Contributor Author

Hey, thanks very much for your PR! Code looks good :) Please just add a new changelog frament at

changes/unreleased/5088.dbco4MBy5FHuS4qawHww3M.toml

with the content

features = "Add Fallback Name Support for Job Callbacks without ``__name__``"
[[pull_requests]]
uid = "5088"
author_uids = ["SmartDever02"]
closes_threads = ["4992"]

thanks for your reply, and I have made it :)

The official Telegram API docs include has_topics_enabled field for User,
but it's not yet implemented in PTB. Adding it to ignored params to fix
test_official test failure.
@Bibo-Joshi Bibo-Joshi merged commit 8511941 into python-telegram-bot:master Jan 7, 2026
3 checks passed
@Bibo-Joshi
Copy link
Member

Thank you very much for the contribution :)

@github-actions github-actions bot locked and limited conversation to collaborators Jan 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide Fallback Name Support for Job Callbacks without __name__

2 participants