On Sun, Dec 12, 2021 at 08:44:25PM -0500, Ricky Teachey wrote:

> I'll go ahead and throw this out there: I was talking to a friend about
> this and he pointed out something simple but astute.
> 
> Will this be expected to work?
> 
> class C:
>     x: Annotated [Any, "spam"]
> 
> help(C.x)
> 
> Obviously it shouldn't as things stand now because that's an
> AttributeError.

You can fix that by giving x a default value.

> But if I'm mucking about in the interpreter and I want to see the docstring
> of a runtime defined (but not import time) attribute, it would be kind of
> nice if it would work. 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.

(Actually, to be clear, I say "we" but I mean the language and the 
stdlib, including help(). "We" as individuals can do anything we like.)

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.

That's the beauty of a decorator. We don't need a PEP or Steering 
Council approval to write a decorator (although we might need one to 
make it a built-in). Just do it!

But to change the language means we have to go through a big cumbersome 
process that may take months or years.

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.


-- 
Steve
_______________________________________________
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/X6BG5L3VW6VWRARLKYFFUP4KRJUHEZVH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to