Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculate message namespace from __qualname__ when not specified #3940

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

arvidfm
Copy link

@arvidfm arvidfm commented Jan 1, 2024

Fixes #3939

Use __qualname__ for the message namespace since it already contains the outer class, making the handler_name processing in _MessagePumpMeta unnecessary

Please review the following checklist.

  • Updated CHANGELOG.md (where appropriate)

else:
# a class defined inside of a function will have a qualified name like func.<locals>.Class,
# so make sure we only use the actual class name(s)
qualname = cls.__qualname__.rsplit("<locals>.", 1)[-1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seem brittle. Is it guaranteed that CPython and all other Python's will have a qualname formatted like this?

Copy link
Author

Choose a reason for hiding this comment

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

It's explicitly defined in the PEP that introduced __qualname__: https://peps.python.org/pep-3155/#proposal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Assigning a message type to a class variable breaks message handlers
3 participants