On Fri, Mar 16, 2018 at 10:54 AM, Игорь Яковченко <truestarecat@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)
            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)
            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.


Christopher Barker, Ph.D.

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