[Tutor] CONSTANTS -- Is it appropriate to use uppercase names within a function or method?
Alan Gauld
alan.gauld at yahoo.co.uk
Tue Nov 12 18:54:04 EST 2019
On 12/11/2019 23:47, Alan Gauld via Tutor wrote:
> On 12/11/2019 21:00, boB Stepp wrote:
>> IF I were to use type annotations as you suggest, would there be any
>> point to the more expansive docstring? The combination of type
>> annotations with already very descriptive variable names seems to make
>> any more description superfluous.
>
> I'm not a big type hints fan so don't use them. But I'm curious to know
> what they do in the context of the help() function. If there is no
> docstring what do type hints generate in help messages?
>
> I suppose I should just try it!...
>
>
OK, Here it is:
>>> def f(x: int, y:str) ->str:
pass
>>> help(f)
Help on function f in module __main__:
f(x:int, y:str) -> str
>>>
So it gives the function prototype. The docstring would,
hopefully, add an explanation of what the function did
(and that is more than just repeating the name of the
function!) but for simple "obvious" functions the
typehints might be sufficient.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list