• How would you name this dictionary?

    From [email protected]@21:1/5 to All on Sun Jan 21 23:39:56 2024
    class NameMe(dict):
    def __missing__(self, key):
    return key

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to [email protected] on Mon Jan 22 11:09:45 2024
    On 21Jan2024 23:39, [email protected] <[email protected]> wrote:
    class NameMe(dict):
    def __missing__(self, key):
    return key

    I would need to know more about what it might be used for. What larger
    problem led you to writing a `dict` subclass with this particular
    `__missing__` implementation?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Cameron Simpson on Mon Jan 22 07:16:51 2024
    Cameron Simpson <[email protected]> writes:
    I would need to know more about what it might be used for. What larger >problem led you to writing a `dict` subclass with this particular >`__missing__` implementation?

    The Python Library Reference (Release 3.13.0a0) contains:

    class Default(dict):
    |... def __missing__(self, key):
    |... return key

    . Otherwise, I personally might think of:

    class DefaultsToKey( dict ):
    |... def __missing__( self, key ):
    |... return key

    .

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)