A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-March/152399.html below:

[Python-Dev] ttk.Treeview.insert() does not allow to insert item with iid=0

[Python-Dev] ttk.Treeview.insert() does not allow to insert item with iid=0Chris Barker chris.barker at noaa.gov
Tue Mar 20 20:02:26 EDT 2018
On Fri, Mar 16, 2018 at 10:54 AM, Игорь Яковченко <truestarecat at gmail.com>
wrote:

> I investigated problem and found that in ttk.py, Treeview.insert(...
> iid=None, ...) in method's body has a check:
>         if iid:
>             res = self.tk.call(self._w, "insert", parent, index,
>                 "-id", iid, *opts)
>         else:
>             res = self.tk.call(self._w, "insert", parent, index, *opts)
> It means that if iid is "True" then use it else autogenerate it.
> Maybe there should be "if iid is not None", not "if iid"? Or there are
> some reasons to do check this way?
>

isn't it considered pythonic to both: use None as a default for "not
specified" AND use:

if something is None

to check if the parameter has been specified?

however, this is a bit of an odd case:

ids are strings, but it allows you to pass in a non-string and stringified
version will be used.

so None should be the only special case -- not "anything false"

(but if the empty string is the root, then it's another special case --
again, good to check for none rather than anything Falsey)

so it probably should do something like:


      if iid is not None:
            res = self.tk.call(self._w, "insert", parent, index,
                "-id", str(iid), *opts)
        else:
            res = self.tk.call(self._w, "insert", parent, index, *opts)

note both the check for None and the str() call.

I'm assuming the str() call happens under the hood at the boundary already,
but better to make it explicit in teh Python.

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.

-CHB

-------
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180321/26cbc1ff/attachment.html>
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4