gh-106727: Add `__module__` check for `inspect.getsource(cls)` by gaogaotiantian · Pull Request #106968 · python/cpython
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test that fails without this fix?
This doesn't fix the case I mentioned (metaclass and class using it, both with the same name and in the same module), but it does fix the case where the metaclass is in a different module and the line numbers just happen to collide with another class of the same name.
I'm not seeing a clear way to fix the "metaclass with same name" case, and I'm also not really worried about it.