Also worth noting is that dict.skip would live in dict.__dict__... which is a dict.
Brandt > On Sep 5, 2019, at 08:51, Andrew Barnert via Python-ideas > <python-ideas@python.org> wrote: > >> On Sep 4, 2019, at 15:25, r...@hwyl.org wrote: >> >> ..."skip" being a unique object defined in and accessible from dict (there >> may be better places to make it available). The dict insertion code then >> simply ignores those entries when creating the dict. > > I’m a bit confused about exactly when this does and doesn’t come into play. > > You say here “the dict insertion code” does it. Would they mean d[key]=d.skip > doesn’t insert anything? If so, then how could I put skip in a dict at all? > If there’s already a d[key] does that get left alone, or deleted? Wouldn’t > this even affect dict inserts that happen behind the scenes, like any time > you tried to assign dict.skip to a global variable or a class or instance > attribute, or pass it as a keyword argument? If an implementation doesn’t use > dict.insert to build dict literals, does that mean it doesn’t work in dict > literals on that implementation, even though that was the whole motivation > for the feature? > > Maybe instead of starting with how it could be implemented, start with where > you ideally do and don’t want it to take effect, and then we can try to work > out how it could be implemented to do that, and how to specify it to require > such an implementation. > > * Obviously you want it in non-comprehension dict displays, because that’s > your example. > * What about comprehensions? > * Constructor calls with the keyword-arg API like dict(a=1, b=dict.skip, > **d2}? > * Constructor calls from iterables of pairs, like dict((1, 2), (3, > dict.skip))? > * Subscription assignments? > * Calls to insert? > * Calls to update? > * Capturing ** keyword args? > * Assignments to globals, attributes, etc. when those use a dict under the > covers (as they usually do!? > * Assignments to such things when they don’t use a dict (as with a slots > class instance)? > > Also, what should happen with this case: > > flag0, flag1 = True, False > d = {'k': 0 if flag0 else dict.skip, > 'k': 1 if flag1 else dict.skip} > > Do we keep the last value for 'k' as usual, and because that’s dict.skip, > therefore d['k'] ends up as a KeyError? Or do we keep the last non-skip value > and therefore d['k'] ends up as 0? > > What about this: > > class D(dict): > skip = 0 > d = D() > d.skip = 1 > d[0] = 0 > d[1] = 1 > d[dict.skip] = dict.skip > > Do we skip the one that uses d.skip, the one that uses type(d).skip (like a > special method lookup), or the one that uses dict.skip? > > > _______________________________________________ > Python-ideas mailing list -- python-ideas@python.org > To unsubscribe send an email to python-ideas-le...@python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/python-ideas@python.org/message/GH3KENFHG6B2PXLV7JYZHQKHSUZ56NQ5/ > Code of Conduct: http://python.org/psf/codeofconduct/ _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/TEDX373AAYX32OARYVABFUDOUDHYBKDT/ Code of Conduct: http://python.org/psf/codeofconduct/