On Friday, September 6, 2019, 11:22:08 AM PDT, Rich Smith <r...@hwyl.org> 
wrote:
> On Thu, 5 Sep 2019 at 16:51, Andrew Barnert <abarn...@yahoo.com> wrote:
>> You say here “the dict insertion code” does it. Would they mean 
>> d[key]=d.skip doesn’t insert anything? > Yes.
OK, then I go from +0 on your proposal to -1.
Constructing dicts with optionally-included values is a bit overly-verbose, no 
matter which of the dict-construction mechanisms you use, and it comes up 
pretty often, so sugar to make it less verbose but just as clear... I don't see 
a burning need for it, but I've got no objections.
But a magic value that can never be stored in any dict? That sounds nice at 
first, but I think once you think it through, it would be a nightmare. 
Especially when you consider how fundamental dicts are to all of Python. 
Globals is a dict. Locals is a dict in some contexts, not others (and the set 
of contexts may even be different in different Python implementations). 
Instance attributes are a dict on most classes, but not all. Class attributes 
are a dict. The namespace passed to the metaclass in a class definition is a 
dict. The values gathered for `**kw` are a dict. And so on.
The rest of your answers are consistent with what you'd expect from this "can 
never go into a dict" design, so I don't have any additional problem with any 
of them; it's just the fundamental idea that I disagree with. :) But one more 
comment:
>> If so, then how could I put skip in a dict at all?
> The intention is that you couldn't. This could raise some implementation 
> issues!
That's putting it mildly.
Forget about figuring out how to make `dict` work (which requires understanding 
the bytecodes and C API functions and so on). Imagine that you're maintaining 
one of the popular pure-Python alternative `collections.abc.Mapping` types on 
PyPI, say, `MySortedDict`. Python 3.9 adds `dict.skip`, and your users quite 
reasonably want you to add the same feature to your type: `MySortedDict.skip is 
dict.skip`, and passing that as a key or value to 
insert/update/construction/etc. skips the same way it does for dict. Does the 
fact that you can't store `dict.skip` in a global, or an attribute of your 
class, or pass it as a keyword argument, etc. get in the way?
> Writing a ConditionalDict type in a similar spirit would be a lot simpler, 
> though less> convenient to use. I will experiment.
If you're interested, it's pretty easy to write an import hook that replaces 
all dict displays with calls to your type's constructor. That's obviously not 
something you'd want to use in real-life code, but I've found it useful for 
playing with ideas like this before. I think one of the repos with a name 
ending in "hack" at abarnert - Overview will get you 90% of the way there, but 
I don't remember exactly what's up there.

| 
| 
| 
|  |  |

 |

 |
| 
|  | 
abarnert - Overview

abarnert has 102 repositories available. Follow their code on GitHub.
 |

 |

 |



_______________________________________________
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/NHTR6IFLG55BFY46WVEREQJEWLKOUFI3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to