Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74333
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <cameron@cskk.homeip.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'float': 0.07; 'chunk': 0.09; 'exit': 0.09; 'thread': 0.14; 'posted': 0.15; 'behave': 0.16; 'downside': 0.16; 'fine.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'in-reply-to:': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'nan': 0.16; 'one)': 0.16; 'operator.': 0.16; 'personally,': 0.16; 'programmer,': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'reply-to:': 0.16; 'simpson': 0.16; 'subject:alternative': 0.16; 'subject:based': 0.16; 'suite.': 0.16; 'undo': 0.16; 'wraps': 0.16; 'obviously': 0.18; 'seems': 0.21; 'example': 0.22; 'rules': 0.22; 'cc:2**1': 0.23; 'header:User-Agent:1': 0.23; 'affects': 0.24; 'cheers,': 0.24; "haven't": 0.24; 'compare': 0.26; "doesn't": 0.30; 'code': 0.31; 'context.': 0.31; 'operators': 0.31; 'themselves': 0.32; 'running': 0.33; 'cases': 0.33; 'plain': 0.33; 'could': 0.34; 'equal': 0.35; 'instances': 0.36; 'received:com.au': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'performance': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'checks': 0.38; 'received:211': 0.38; 'window': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'how': 0.40; 'even': 0.60; 'easy': 0.60; 'tell': 0.60; 'affect': 0.61; 'break': 0.61; 'extended': 0.61; 'new': 0.61; 'entire': 0.61; 'content- disposition:inline': 0.62; 'kind': 0.63; 'more': 0.64; 'occur': 0.65; 'within': 0.65; 'effectively': 0.66; 'here': 0.66; 'special': 0.74; 'day': 0.76; 'introduce': 0.78; '_if_': 0.84; 'have?': 0.84; 'response,': 0.91; 'subject:Proposal': 0.91 |
| Date | Fri, 11 Jul 2014 10:20:36 +1000 |
| From | Cameron Simpson <cs@zip.com.au> |
| To | python-list@python.org |
| Subject | context manager based alternative to Re: Proposal: === and !=== |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii; format=flowed |
| Content-Disposition | inline |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| X-Optus-CM-Score | 0 |
| X-Optus-CM-Analysis | v=2.1 cv=eojmkOZX c=1 sm=1 tr=0 a=YuQlxtEQCowy2cfE5kc7TA==:117 a=YuQlxtEQCowy2cfE5kc7TA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=LcaDllckn3IA:10 a=93hXxCVcUUMA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=vrctD-FHyJUrA2K5w6AA:9 a=CjuIK1q_8ugA:10 |
| Cc | Steven D'Aprano <steve+comp.lang.python@pearwood.info>, "Anders J. Munch" <2014@jmunch.dk> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11744.1405038048.18130.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1405038048 news.xs4all.nl 2831 [2001:888:2000:d::a6]:45725 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:74333 |
Show key headers only | View raw
operators
Reply-To:
In-Reply-To: <20140709231623.GA66358@cskk.homeip.net>
I posted this the other day and haven't seen a response, not even a scathing
rejection...
Here's an alternative proposal that doesn't involve a new operator.
Consider this code snippet:
with float.behaviour(nan_eq=True):
... code here ...
This is intended to set a thread-local behaviour flag on the entire float type
and undo it on exit from the context.
This has the following advantages:
- it is very easy to use, and makes plain that this particular chunk of code has special rules
- it makes NaN == behave as requested in a particular window
- it effectively wraps all code called inside the suite
- because it is thread local it doesn't asynchronously affect other running code
- it doesn't introduce a new operator
- it affects a tightly constrainted behaviour, and can obviously be extended to other special cases if they arise, for example to only make the same flavour of NaN compare equal
- if the special Nan != Nan checks occur only in the Nan instances themselves (eg by monkey patching __eq__ onto one) then it should not affect performance outside the NaN instances
The downside is that it could break code depending on NaN being
nonreflexive _if_ that code is called within the suite.
Personally, I would take this over a new and only-subtly-different-from-==
"===" operator. It also seems to give more control to the programmer, in that
they can set the domain in which the behaviour obtains.
Cheers,
Cameron Simpson <cs@zip.com.au>
Q: How many user support people does it take to change a light bulb?
A: We have an exact copy of the light bulb here and it seems to be
working fine. Can you tell me what kind of system you have?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
context manager based alternative to Re: Proposal: === and !=== Cameron Simpson <cs@zip.com.au> - 2014-07-11 10:20 +1000
Re: context manager based alternative to Re: Proposal: === and !=== Roy Smith <roy@panix.com> - 2014-07-10 21:17 -0400
Re: context manager based alternative to Re: Proposal: === and !=== Chris Angelico <rosuav@gmail.com> - 2014-07-11 14:37 +1000
csiph-web