typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Should __module__ be defined as class attribute?

Open dvarrazzo opened this issue 1 year ago • 3 comments

Ref. https://github.com/python/typeshed/blob/58f2a795bac5924367d21961af53a32af7bb5727/stdlib/builtins.pyi#L98

This results in mypyc raising an error upon code accessing obj.__class__.__module__, which I believe is the canonical way to get the attribute. See https://github.com/mypyc/mypyc/issues/1055

Note that Cython doesn't define obj.__module__, therefore it makes difficult to write portable code.

dvarrazzo avatar Jun 11 '24 08:06 dvarrazzo

See https://github.com/python/typeshed/pull/8787 and #8789 for previous discussion

AlexWaygood avatar Jun 11 '24 08:06 AlexWaygood

Maybe we could revisit #8789? Seems like a mypy problem that may or may not be fixed in the meantime, but should probably be fixed in any case.

srittau avatar Jun 11 '24 08:06 srittau

Yeah I'm definitely open to revisiting either #8787 or #8789! The current stubs are incorrect, for sure.

AlexWaygood avatar Jun 11 '24 08:06 AlexWaygood

Maybe object should just get that attribute, though I guess that only helps in the future …

SamB avatar Feb 07 '25 00:02 SamB