<div dir="ltr">On Fri, Mar 16, 2018 at 10:54 AM, Игорь Яковченко <span dir="ltr"><<a href="mailto:truestarecat@gmail.com" target="_blank">truestarecat@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_signature"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail-m_-2992503333945316708gmail_signature"><div dir="ltr">I investigated problem and found that in ttk.py, Treeview.insert(... iid=None, ...) in method's body has a check:<div dir="ltr">        if iid:</div><div dir="ltr">            res = self.tk.call(self._w, "insert", parent, index,</div><div dir="ltr">                "-id", iid, *opts)</div><div dir="ltr">        else:</div><div dir="ltr">            res = self.tk.call(self._w, "insert", parent, index, *opts)</div><div dir="ltr">It means that if iid is "True" then use it else autogenerate it.</div><div>Maybe there should be "if iid is not None", not "if iid"? Or there are some reasons to do check this way?</div></div></div></div></blockquote><div> <br>isn't it considered pythonic to both: use None as a default for "not specified" AND use:<br><br></div><div>if something is None<br><br></div><div>to check if the parameter has been specified?<br><br></div><div>however, this is a bit of an odd case:<br><br></div><div>ids are strings, but it allows you to pass in a non-string and stringified version will be used.<br><br></div><div>so None should be the only special case -- not "anything false"<br><br></div><div>(but if the empty string is the root, then it's another special case -- again, good to check for none rather than anything Falsey)<br></div><div><br></div><div>so it probably should do something like:<br><br></div><div><br></div><div><span style="font-family:monospace,monospace">      if iid is not None:</span><div dir="ltr"><span style="font-family:monospace,monospace">            res = self.tk.call(self._w, "insert", parent, index,</span></div><div dir="ltr"><span style="font-family:monospace,monospace">                "-id", str(iid), *opts)</span></div><div dir="ltr"><span style="font-family:monospace,monospace">        else:</span></div><div dir="ltr"><span style="font-family:monospace,monospace">            res = self.tk.call(self._w, "insert", parent, index, *opts)</span></div><br></div><div>note both the check for None and the str() call.<br></div><div> <br></div><div>I'm assuming the str() call happens under the hood at the boundary already, but better to make it explicit in teh Python.<br><br></div><div>Alternatively: this has been around a LONG time, so the maybe the answer is "don't do that" -- i.e. don't use anything falsey as an iid. But it would still be good to make the docs more clear about that.<br><br></div><div>-CHB<br><br></div>-------<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">Chris.Barker@noaa.gov</a></div>
</div></div>