◐ Shell
clean mode source ↗

gh-104549: Set __module__ on TypeAliasType by JelleZijlstra · Pull Request #104550 · python/cpython

@AlexWaygood unfortunately this no longer works, I get

test test_type_aliases failed -- Traceback (most recent call last):
  File "/Users/jelle/py/cpython/Lib/test/test_type_aliases.py", line 211, in test_module
    self.assertEqual(TypeAliasType.__module__, "typing")
AssertionError: <attribute '__module__' of 'typing.TypeAliasType' objects> != 'typing'

This seems to be an inescapable consequence of how heap types work (

if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
), so not sure how to get around it.

@Eclips4 good call about tests in another module, I'll add some.

As for the module being NULL, apparently that can happen in various exotic situations where there is no calling function or that function has no module. Not 100% sure how to reproduce that.