Steven D'Aprano writes: > On Sun, Dec 12, 2021 at 08:44:25PM -0500, Ricky Teachey wrote:
> > class C: > > x: Annotated [Any, "spam"] > > > > help(C.x) > > > And it seems reasonable to try and create a way for it to work. > > By default, for arbitrary classes, no, it *shouldn't* work, because for > arbitrary classes we cannot treat type hints as doc strings. Why not? In the sense that we establish a standard protocol for attaching them, and if there isn't one there, then 'help' would ignore that attribute or provide an empty docstring or whatever default action seems appropriate (presumably it would at least tell us the type! even if the hint is not an Annotated). > At least not without buy in from the core devs, including people like > Guido who care very much about typing. And that will probably need a > PEP. It's true that changing help will require buy-in from the core devs, as it's a built-in. But: > But to change the language Where's the language change? What am I missing? Or are you using this loosely to include builtins or even the whole stdlib? It needs one thing: a standard place to put the documentation. I don't think just stuffing a string in __metadata__ is a good idea; that will be an annoyance to existing users of the __metadata__ attribute. I think it probably should be an attribute on Annotated instances, to avoid tromping on existing uses of the __metadata__ attribute, while allowing existing users of Annotated to take advantage of the documentation function in a gradual way. While I agree this is going to need input from core devs that would likely delay things by months rather than weeks, I see no reason why it wouldn't be in 3.12. In fact, it seems likely that this change would be small and straightforward enough that it could be prototyped, polished, and wrapped in time for 3.11. I don't think it would be that hard to get buy-in to a plausible proposal, getting Guido's attention is probably harder. ;-) (If he kibozes this post I'll cry and then laugh.) > A *lightweight* change that doesn't actually change the language > could be accepted without a PEP. If you submitted a PR to update > help() so that it was smart enough to recognise strings as the > second parameter of Annotated annotations and treat them as > docstrings, I suspect that would be allowed as just a relatively > small new feature. I don't think that will fly, as it would be rude to people who are already using Annotated for something else (especially if they've already transitioned from direct use of annotations!) I don't think Python the language or the stdlib should touch the __metadata__ attribute, it should be reserved to client code. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YDMZATBBUEXFGLU3WCCGSL2DELN3JQ54/ Code of Conduct: http://python.org/psf/codeofconduct/