Devin Jeanpierre wrote:
Um -- if you don't want a and c being passed in, why put them in the
function signature?
He wants both or neither to be passed in.
Ah -- right.
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list
GZ writes:
> I run into a weird problem. I have a piece of code that looks like the
> following:
>
> f(, a=None, c=None):
> assert (a==None)==(c==None)
>
There is only one 'None' - so use 'a is None' rather than 'a == None'.
(In common lisp there is a particular language construct tha
In article ,
Devin Jeanpierre wrote:
> > Um -- if you don't want a and c being passed in, why put them in the
> > function signature?
>
> He wants both or neither to be passed in.
assert sum(foo is None for foo in [a, c]) % 2 == 0
--
http://mail.python.org/mailman/listinfo/python-list
> Um -- if you don't want a and c being passed in, why put them in the
> function signature?
He wants both or neither to be passed in.
-- Devin
On Sun, Dec 25, 2011 at 11:27 PM, Ethan Furman wrote:
> GZ wrote:
>>
>> Hi,
>>
>> I run into a weird problem. I have a piece of code that looks like th
Nobody wrote:
nothing should compare
equal to None except for None itself, so "x is None" and "x == None"
shouldn't produce different results unless there's a bug in the comparison
method.
Why wouldn't you want other types that can compare equal to None? It
could be useful for a Null type to
GZ wrote:
Hi,
I run into a weird problem. I have a piece of code that looks like the
following:
f(, a=None, c=None):
assert (a==None)==(c==None)
Um -- if you don't want a and c being passed in, why put them in the
function signature?
~Ethan~
--
http://mail.python.org/mailman/list
On Sun, Dec 25, 2011 at 2:38 AM, Nobody wrote:
> On Sat, 24 Dec 2011 23:09:50 -0800, GZ wrote:
>
>> I run into a weird problem. I have a piece of code that looks like the
>> following:
>>
>> f(, a=None, c=None):
>> assert (a==None)==(c==None)
>>
>>
>> The problem is that == is not impleme
> Which of course leads to a SillyPEP for a new keyword, "are", which
> would allow you to write:
>
a and c are None
>
> instead of the much more verbose
>
a is None and c is None
How about:
>>> a is b is None
;)
-- Devin
On Sun, Dec 25, 2011 at 7:27 PM, Roy Smith wrote:
> In ar
On Sun, 25 Dec 2011 15:45:10 -0800, Larry Hudson wrote:
> On 12/24/2011 11:09 PM, GZ wrote:
>> Hi,
>>
>> I run into a weird problem. I have a piece of code that looks like the
>> following:
>>
>> f(, a=None, c=None):
>> assert (a==None)==(c==None)
>>
> <...>
>
> At first glance this loo
Am 25.12.2011 15:04, schrieb Chris Angelico:
> I think there are certain types that are actually not implemented as
> classes, and hence cannot be subclassed. This is almost certainly an
> implementation detail though; my testing was done in Py3.2 (on Windows
> fwiw).
Some extension types are not
In article ,
Devin Jeanpierre wrote:
> The issue here is that "== None" is being used instead of "is None",
> but I believe that's been covered. Your response doesn't include it,
> so maybe it's worth restating.
Which of course leads to a SillyPEP for a new keyword, "are", which
would allow yo
> At first glance this looked like it should be a simple boolean "and", but
> then I realized that when a and c are both unequal to None, the result would
> also be True. This implies the logical approach would be exclusive-or (^).
Among booleans, "!=" is exclusive or and "==" is its negation. I
On 12/24/2011 11:09 PM, GZ wrote:
Hi,
I run into a weird problem. I have a piece of code that looks like the
following:
f(, a=None, c=None):
assert (a==None)==(c==None)
<...>
At first glance this looked like it should be a simple boolean "and", but then I realized that
when a and
On 12/26/2011 01:13 AM, Roy Smith wrote:
In article,
Chris Angelico wrote:
On Mon, Dec 26, 2011 at 12:17 AM, Roy Smith wrote:
Just for fun, I tried playing around with subclassing NoneType and
writing an __eq__ for my subclass. Turns out, you can't do that:
Traceback (most recent call la
On Mon, Dec 26, 2011 at 1:13 AM, Roy Smith wrote:
> If you were designing the interface from scratch, you would probably
> represent that with an exception hierarchy
Or possibly with "returns a False value", giving the option of None
for none available, False for none will ever be available. Of c
In article ,
Chris Angelico wrote:
> On Mon, Dec 26, 2011 at 12:17 AM, Roy Smith wrote:
> > Just for fun, I tried playing around with subclassing NoneType and
> > writing an __eq__ for my subclass. Turns out, you can't do that:
> >
> > Traceback (most recent call last):
> > File "./none.py",
On Mon, Dec 26, 2011 at 12:48 AM, Steven D'Aprano
wrote:
> I can't think of any other un-subclassable classes other than NoneType.
> Which ones are you thinking of?
I don't remember, but it was mentioned in a thread a little while ago.
Experimentation shows that 'bool' is one of them, though. Thi
On Mon, 26 Dec 2011 00:35:46 +1100, Chris Angelico wrote:
[...]
>> TypeError: Error when calling the metaclass bases
>> type 'NoneType' is not an acceptable base type
>
> Yes; unfortunately quite a few Python built-in classes can't be
> subclassed.
I can't think of any other un-subclassable
On Mon, Dec 26, 2011 at 12:17 AM, Roy Smith wrote:
> Just for fun, I tried playing around with subclassing NoneType and
> writing an __eq__ for my subclass. Turns out, you can't do that:
>
> Traceback (most recent call last):
> File "./none.py", line 5, in
> class Nihil(NoneType):
> TypeErro
In article ,
Lie Ryan wrote:
> Now, whether doing something like that is advisable or not, that's a
> different question; however nothing in python states that you couldn't
> have something that compare equal to None whether there is a bug or not
> in the comparison method.
Just for fun, I t
On 12/25/2011 08:38 PM, Nobody wrote:
nothing should compare equal to None except for None itself, so "x is None"
> and "x == None" shouldn't produce different results unless there's a
> bug in the comparison method.
not necessarily, for example:
import random
class OddClass:
def __eq__(s
On Sat, 24 Dec 2011 23:09:50 -0800, GZ wrote:
> I run into a weird problem. I have a piece of code that looks like the
> following:
>
> f(, a=None, c=None):
> assert (a==None)==(c==None)
>
>
> The problem is that == is not implemented sometimes for values in a
> and c, causing an excep
GZ writes:
> assert (a==None)==(c==None)...
> So how do I reliably test if a value is None or not?
Equality is the wrong comparison to start with. Use "a is None".
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
I run into a weird problem. I have a piece of code that looks like the
following:
f(, a=None, c=None):
assert (a==None)==(c==None)
The problem is that == is not implemented sometimes for values in a
and c, causing an exception NotImplementedError.
I ended up doing assert (not a)==
24 matches
Mail list logo