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

Merged
merged 10 commits into from
Jul 17, 2024

Conversation

arvidfm
Copy link
Contributor

@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
Contributor 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

@darrenburns
Copy link
Member

Sorry for the delay on this - this is quite the gotcha!

I've confirmed it fixes the issue and tested it in a complex app. I also updated the CHANGELOG. If the tests pass I think we're good to merge.

@darrenburns darrenburns self-assigned this Jul 17, 2024
Copy link
Member

@darrenburns darrenburns left a comment

Choose a reason for hiding this comment

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

LGTM

@darrenburns darrenburns merged commit c9bb137 into Textualize:main Jul 17, 2024
19 checks passed
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