From: Jeff Epler <jepler@unpythonic.net>
To: John Kacur <jkacur@redhat.com>
Cc: RT <linux-rt-users@vger.kernel.org>,
Clark Williams <williams@redhat.com>,
Atsushi Nemoto <atsushi.nemoto@sord.co.jp>
Subject: Re: [PATCH] rteval: Add __contains__ in rtevalConfig
Date: Thu, 29 Jul 2021 19:54:57 -0500 [thread overview]
Message-ID: <20210730005457.c5kog456adkun4bd@unpythonic.net> (raw)
In-Reply-To: <20210729220713.822137-1-jkacur@redhat.com>
On Thu, Jul 29, 2021 at 06:07:13PM -0400, John Kacur wrote:
> Add the __contains__ function to the rtevalCfgSection class to make "in"
> function correctly.
Thank you. A possible correction:
I believe the correct implementation (to delegate the 'in' operation to
the dictionary-like object self.__cfgdata) is
def __contains__(self, key):
return key in self.__cfgdata
I mocked a bit of rtevalCfgSection with your implementation:
class rtevalCfgSection:
def __init__(self, cfgdata):
self.__cfgdata = cfgdata
def __contains__(self, key):
if key in self.__cfgdata.keys():
return self.__cfgdata[key]
return None
and then tried it with some carefully chosen values
>>> d = {1: 'x', 2: 'y', 3: None, 4: False}
>>> r = rtevalConfig.rtevalCfgSection(d)
>>> 1 in d, 1 in r
(True, True)
>>> 9 in d, 9 in r
(False, False)
>>> 3 in d, 3 in r
(True, False)
With the corrected implementation, the results would always be the same,
not different in the '3' case.
Additionally, my version avoids extra operation on the underlying
dictionary.
Jeff
next prev parent reply other threads:[~2021-07-30 1:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-29 22:07 [PATCH] rteval: Add __contains__ in rtevalConfig John Kacur
2021-07-30 0:54 ` Jeff Epler [this message]
2021-07-30 3:04 ` John Kacur
-- strict thread matches above, loose matches on Subject: below --
2021-07-30 3:05 John Kacur
2021-07-30 5:03 ` Atsushi Nemoto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210730005457.c5kog456adkun4bd@unpythonic.net \
--to=jepler@unpythonic.net \
--cc=atsushi.nemoto@sord.co.jp \
--cc=jkacur@redhat.com \
--cc=linux-rt-users@vger.kernel.org \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.