<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
On 05.06.2018 17:56, Chris Barker wrote:<br>
<blockquote type="cite"
cite="mid:CALGmxE+F9Li2dVM=JAN63sroe1UPHppeaLyQckybpi7V8ud+9A@mail.gmail.com">
<div dir="ltr">
<div>
<div>
<div>OK,<br>
<br>
</div>
looking a bit deeper:<br>
<br>
In [69]: timedelta.__new__.__doc__<br>
Out[69]: 'Create and return a new object. See help(type)
for accurate signature.'<br>
<br>
In [70]: timedelta.__init__.__doc__<br>
Out[70]: 'Initialize self. See help(type(self)) for
accurate signature.'<br>
<br>
In [71]: timedelta.__doc__<br>
Out[71]: 'Difference between two datetime values.'<br>
<br>
</div>
So the none of the docstrings have the proper information.
And:<br>
<br>
</div>
help(timedelta) returns:<br>
<br>
Help on class timedelta in module datetime:<br>
<br>
class timedelta(builtins.object)<br>
| Difference between two datetime values.<br>
| <br>
| Methods defined here:<br>
| <br>
| __abs__(self, /)<br>
| abs(self)<br>
| <br>
| __add__(self, value, /)<br>
| Return self+value.<br>
....<br>
<br>
<div>So no signature either.<br>
<br>
</div>
<div>I'm guessing this is because argument clinic has not been
properly applied -- so Ihave a PR to work on.<br>
<br>
</div>
<div>but where does help() get its info anyway?<br>
<br>
</div>
<div>I always thought docstrings were supposed to be used for
the basic, well, docs. And between the class and __new__ and
__init__, somewhere in there you should learn how to
initialize an instance, yes?<br>
<br>
</div>
</div>
</blockquote>
<p>In [5]: print(str.__doc__)<br>
str(object='') -> str<br>
str(bytes_or_buffer[, encoding[, errors]]) -> str<br>
<br>
Create a new string object from the given object. If encoding or<br>
errors is specified <...></p>
<p>As you can see, the start of the type's docstring contains
constructor signature(s).</p>
<p>Timedelta's one should probably do the same.<br>
</p>
<blockquote type="cite"
cite="mid:CALGmxE+F9Li2dVM=JAN63sroe1UPHppeaLyQckybpi7V8ud+9A@mail.gmail.com">
<div dir="ltr">
<div>-CHB<br>
<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Mon, Jun 4, 2018 at 6:21 PM,
Matthias Bussonnier <span dir="ltr"><<a
href="mailto:bussonniermatthias@gmail.com" target="_blank"
moz-do-not-send="true">bussonniermatthias@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><br>
<br>
<div class="gmail_quote"><span class="">
<div dir="ltr">On Mon, 4 Jun 2018 at 17:29, Ivan
Pozdeev via Python-Dev <<a
href="mailto:python-dev@python.org"
target="_blank" moz-do-not-send="true">python-dev@python.org</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"> On 05.06.2018
3:09, Matthias Bussonnier wrote:<br>
<blockquote type="cite">
<div dir="ltr">This may even be a bug/feature of
IPython,
<div><br>
</div>
<div>I see that inspect.signature(timedelta)
fails, so if <span
style="font-family:monospace,monospace">timedelta?
says</span></div>
<div><span
style="color:rgb(34,34,34);font-family:monospace,monospace;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Init
signature: timedelta(self, /, *args,
**kwargs)</span></div>
<div><span
style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Then
this may be some IPython internal logic.
The timedelta class seem to use __new__
instead of __init__ (not sure why)</span></div>
</div>
</blockquote>
<p>Because it's an immutable type.</p>
</div>
</blockquote>
</span>
<div>Ah, yes, thanks. </div>
<span class="">
<div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<blockquote type="cite">
<div dir="ltr">
<div><span
style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">
and __new__ have a meaningful signature, </span><br>
</div>
<div><span
style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">So
maybe we should fallback on that during
signature inspection.</span></div>
<div><span
style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br>
</span></div>
</div>
</blockquote>
<p>According to
<a
class="m_8719785607118336130m_-5298358443040669888moz-txt-link-freetext"
href="https://stackoverflow.com/questions/4374006/check-for-mutability-in-python"
target="_blank" moz-do-not-send="true">https://stackoverflow.com/<wbr>questions/4374006/check-for-<wbr>mutability-in-python</a>
,<br>
there are no reliable tests for mutability.</p>
</div>
</blockquote>
</span>
<div>Sure, but we can test if the signature of __init__
is (self,/, *args, **kwargs), and if it is, it is
useless we can attempt to get the signature from
__new__ and show that instead. We do similar things
for docstrings, if __init__ have no docstring we look
at the class level docstring. </div>
<span class="HOEnZb"><font color="#888888">
<div>-- </div>
<div>M</div>
<div><br>
</div>
<div> </div>
</font></span></div>
</div>
<br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org"
moz-do-not-send="true">Python-Dev@python.org</a><br>
<a
href="https://mail.python.org/mailman/listinfo/python-dev"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a
href="https://mail.python.org/mailman/options/python-dev/chris.barker%40noaa.gov"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>chris.barker%40noaa.gov</a><br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
<div class="gmail_signature" data-smartmail="gmail_signature"><br>
Christopher Barker, Ph.D.<br>
Oceanographer<br>
<br>
Emergency Response Division<br>
NOAA/NOS/OR&R (206) 526-6959 voice<br>
7600 Sand Point Way NE (206) 526-6329 fax<br>
Seattle, WA 98115 (206) 526-6317 main reception<br>
<br>
<a href="mailto:Chris.Barker@noaa.gov" target="_blank"
moz-do-not-send="true">Chris.Barker@noaa.gov</a></div>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Regards,
Ivan</pre>
</body>
</html>