Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Marko Rauhamaa
Ethan Furman :

> On 07/27/2019 02:10 PM, Chris Angelico wrote:
>> When talking about indistinguishable objects, is it correct to talk
>> about "the " or "an "?
>
> Multiple indistinguishable objects are still multiple, so "an".
>
> Implementation details should only enter the conversation when
> specifically discussing the implementation -- so CPython is an
> implementation detail while Python is the language.

Yes. If the API guarantees singleton-ness (reliable testability through
"is"), the correct article is "the", otherwise "an".

There is no guarantee that two empty strings are the same object so "an
empty string" is the right expression.

Now, len(string) return "the length" of the string of "a length" of the
string:

   >>> s = "*"*2000
   >>> len(s)
   2000
   >>> len(s) is len(s)
   False

Here "the length" is the right answer and must be understood as a
contraction of the pedantic: "an integer representing the length".

So it depends on the context if the relevant equivalence is "is" or
"==". Maybe the rule of thumb is that if we are talking about strings,
integers and similar things, we should think about it from the point of
view of Python's data model (objects; "is"). But when we talk about
things like "length", "square root", "sum" or "name", the point of view
is the abstractions the objects are standing for ("==").


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Peter Otten
Chris Angelico wrote:

> When talking about indistinguishable objects, is it correct to talk
> about "the " or "an "?
> 
> Example:
> 
> def f(s):
> """Frob a thing.
> 
> If s is an empty string, frobs all the things.
> OR
> If s is the empty string, frobs all the things.
> """

Slightly OT: 

While I would write "an empty string" but happily accept "the empty string" 
I stumbled upon "all *the* things". Shouldn't it be "all things"?

Real question as I'm not a native speaker.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Cameron Simpson

On 28Jul2019 10:32, Peter Otten <__pete...@web.de> wrote:

Chris Angelico wrote:


When talking about indistinguishable objects, is it correct to talk
about "the " or "an "?

Example:

def f(s):
"""Frob a thing.

If s is an empty string, frobs all the things.
OR
If s is the empty string, frobs all the things.
"""


Slightly OT:

While I would write "an empty string" but happily accept "the empty string"
I stumbled upon "all *the* things". Shouldn't it be "all things"?

Real question as I'm not a native speaker.


The collection is "the things". "all" qualifies it, versus, say, "some 
of the things" or "the first of the things" etc.


You do also get "all things". It is less common. It tends to mean _all_ 
things, not just the ones here. So "all people" means everyone 
everywhere. But "all the people" usually refers to some specific group.  
What group depends on context.


So some examples:

   def f(s, things):
 ''' Frob the things.
 '''

I would expect to frob the things passed as the parameter (thus, the 
context).


Versus:

   class Thing:
 ...

   def f(s):
 ''' Frob all Things.
 '''

I would expect there to be some global registry of Thing instances, and 
to frob them all.


Chris' example is a bit incomplete because there's no context to 
indicate what group "the things" comprise.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Michael F. Stemper
On 27/07/2019 17.43, Stefan Ram wrote:
> Terry Reedy  writes:
>> In mathematics, *every* set is 'the'.

This is correct, at least in ZF, where the Axiom of Extensionality says
that (in English) if A and B have exactly the same elements, they are
the same set.

> |Example 2   Let T be an non-empty set and ...
> [PDF] Real Analysis on Metric Spaces - Columbia University

It's obvious that "an" is a typo, either for "any" or "a". Assume for
the sake of argument that it's intended to be "a", as in "Let T be a
non-empty set..." T is indeed "a" set, but it's the only set that has
the same elements as T. Therefore, once you've let T be some specific
non-empty set, it is *the* set T.


-- 
Michael F. Stemper
Life's too important to take seriously.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread MRAB

On 2019-07-28 13:30, Cameron Simpson wrote:

On 28Jul2019 10:32, Peter Otten <__pete...@web.de> wrote:

Chris Angelico wrote:


When talking about indistinguishable objects, is it correct to talk
about "the " or "an "?

Example:

def f(s):
"""Frob a thing.

If s is an empty string, frobs all the things.
OR
If s is the empty string, frobs all the things.
"""


Slightly OT:

While I would write "an empty string" but happily accept "the empty string"
I stumbled upon "all *the* things". Shouldn't it be "all things"?

Real question as I'm not a native speaker.


The collection is "the things". "all" qualifies it, versus, say, "some
of the things" or "the first of the things" etc.


[snip]

It's strange that "all the things" (meaning "all of the things") is OK, 
but otherwise it's "one of the things", "some of the things", etc.


That's English for you!
--
https://mail.python.org/mailman/listinfo/python-list


Boolean comparison & PEP8

2019-07-28 Thread Jonathan Moules

Hi List,
Lets say I want to know if the value of `x` is bool(True).
My preferred way to do it is:

if x is True:
    pass

Because this tests both the value and the type.

But this appears to be explicitly called out as being "Worse" in PEP8:

"""
Don't compare boolean values to True or False using ==.

Yes:   if greeting:
No:    if greeting == True:
Worse: if greeting is True:
"""

Why?

If `x` can also have a value of "1"(str) or 1(int) then in both cases 
this would be a false positive if I were to do the below as they'll both 
equate to True:


if x:
    pass

The PEP for boolean type (285 - 
https://www.python.org/dev/peps/pep-0285/) doesn't mention the "is" 
comparison keyword at all as far as I can tell.


What am I missing?
Thanks



--
https://mail.python.org/mailman/listinfo/python-list


Trouble installing python

2019-07-28 Thread Steven via Python-list
Good afternoon,

I originally started with the latest version of python (3.7), but I was unable 
to figure out how to get to script mode.  There weren't any tabs at the top of 
the interactive mode window.

So I decided to uninstall 3.7, and try 3.5.2 (since that is the version my 
online instructor is using)  now i keep getting a screen asking me to modify, 
repair, or uninstall (screen shoot attached).  I have clicked repair twice now, 
and modify once and I still get the same message.

Am I doing something wrong in 3.7 that is maybe hiding script mode?

Thank you

Steven

Sent from ProtonMail mobile
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trouble installing python

2019-07-28 Thread MRAB

On 2019-07-28 18:45, Steven via Python-list wrote:

Good afternoon,

I originally started with the latest version of python (3.7), but I was unable 
to figure out how to get to script mode.  There weren't any tabs at the top of 
the interactive mode window.


What is "script mode"? Are you using IDLE?

If you are, then look in the menu for File->New.


So I decided to uninstall 3.7, and try 3.5.2 (since that is the version my 
online instructor is using)  now i keep getting a screen asking me to modify, 
repair, or uninstall (screen shoot attached).  I have clicked repair twice now, 
and modify once and I still get the same message.


This list is text-only; it removes any attached pictures.


Am I doing something wrong in 3.7 that is maybe hiding script mode?


--
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Marko Rauhamaa
Jonathan Moules :

> Lets say I want to know if the value of `x` is bool(True).
> My preferred way to do it is:
>
> if x is True:
> [...]
>
> But this appears to be explicitly called out as being "Worse" in PEP8:
>
> [...]
>
> Why?

It has primarily to do with the naturalness of expression. In English,
you say:

   If you have a moment, I'll show you.

   If you had a dog, you'd understand.

instead of:

   If your having a moment is true, I'll show you.

   If your having a dog were true, you'd understand.

By the same vein, in Python you say:

   if len(students) < 7:
   klass.cancel()

rather than:

   if (len(students) < 7) is True:
   klass.cancel()


Furthermore, while True and False are singleton objects, referring to
them through the "is" operator seems strikingly ontological in most
contexts. You are no longer interested in the message of the letter but
the fibers of the paper it was written on.

I *could* imagine a special case where a positional argument's semantics
would depend on the specific object. For example,

   >>> os.path.exists(False)
   True

is rather funky and the os.path.exists function would probably benefit
from a check such as:

   if path is True or path is False:
   raise Hell()

but even in such cases, it is more customary to say:

   if isinstance(path, bool):
   raise Hell()


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: bool(Enum) should raise ValueError

2019-07-28 Thread Erik Aronesty
class Status:
  valid = 1
  invalid = 2
  unknown = 3




On Fri, Jul 26, 2019, 3:37 PM Chris Angelico  wrote:

> On Sat, Jul 27, 2019 at 5:16 AM Erik Aronesty  wrote:
> >
> > I just spend a while tracking down and killing all "if Enum" and "if not
> > Enum" bugs in my code.   I was frankly shocked that this didn't raise a
> > ValueError to begin with.
> >
> > Apparently all enums are true/false depending on whether the underlying
> > value is truthy or falsy.
> >
> > Which breaks the abstraction Enum's are trying to achieve because now the
> > user of an Enum has to know "stuff" about the underlying value and how it
> > behaves.
>
> If you want to abstract away the underlying value, just don't have one?
>
> >>> from enum import Enum, auto
> >>> class Color(Enum):
> ... red = auto()
> ... green = auto()
> ... blue = auto()
> ...
> >>> bool(Color.red)
> True
> >>> bool(Color.green)
> True
> >>> bool(Color.blue)
> True
>
> They happen to have the values 1, 2, and 3, but that doesn't matter.
>
> When an enum has to correspond to a real underlying value, it behaves
> as similarly to that value as possible:
>
> >>> http.HTTPStatus.METHOD_NOT_ALLOWED == 405
> True
>
> Thus it should also inherit its truthiness from that value.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: bool(Enum) should raise ValueError

2019-07-28 Thread Ethan Furman

On 07/28/2019 01:46 PM, Erik Aronesty wrote:

One possibility
---


class Status:
   valid = 1
   invalid = 2
   unknown = 3


  if status is Status.valid:
  # good status, do something
  elif status is Status.unknown:
  figure_out_status()
  elif status is Status.invalid:
  raise ValueError('this shouldn't happen!)
  else:
  raise ValueError('unhandled Status: %r' % status)

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Thomas Jollans
On 28/07/2019 17:13, MRAB wrote:
> [snip]
> 
> It's strange that "all the things" (meaning "all of the things") is OK,
> but otherwise it's "one of the things", "some of the things", etc.

Is it?

It's the same in French, Dutch and German. Can't tell if it just makes
sense or if it's Common Average European doing its thing.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Chris Angelico
On Sun, Jul 28, 2019 at 5:36 PM Marko Rauhamaa  wrote:
> So it depends on the context if the relevant equivalence is "is" or
> "==". Maybe the rule of thumb is that if we are talking about strings,
> integers and similar things, we should think about it from the point of
> view of Python's data model (objects; "is"). But when we talk about
> things like "length", "square root", "sum" or "name", the point of view
> is the abstractions the objects are standing for ("==").

Interesting. So in your view, a string object representing zero
characters is "an", but its length is "the"? I'd have thought that
both are considered value types, where identity is immaterial.

Thanks for all the insights, all. This is a curious point of English
and one that I've definitely seen people on both sides of.

My apologies for not responding earlier or to individual posts. For a
while (and I'm actually not certain that this post will make it), all
Gmail addresses have been unable to post to python-list, and even
contacting the list-owner wasn't possible.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Michael Torrie
On 7/28/19 5:55 AM, Jonathan Moules wrote:
> But this appears to be explicitly called out as being "Worse" in PEP8:
> 
> """
> Don't compare boolean values to True or False using ==.
> 
> Yes:   if greeting:
> No:    if greeting == True:
> Worse: if greeting is True:
> """

Yet the recommended solution to the problem of wanting a default
argument of an empty list is something like this:

def foo(bar=False);
if bar is False:
bar = []



Clearly in this case the expression "not bar" would be incorrect.

There's a difference between looking for a particular identity or
sentinel, and checking for truthiness or falsiness.

So I guess it all depends on what you need to do. If you just need to
check truthiness, just do "if greeting"  If you need to know if the
variable is some particular sentinel, use the "if greeting is whatever".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread MRAB

On 2019-07-29 00:04, Chris Angelico wrote:

On Sun, Jul 28, 2019 at 5:36 PM Marko Rauhamaa  wrote:

So it depends on the context if the relevant equivalence is "is" or
"==". Maybe the rule of thumb is that if we are talking about strings,
integers and similar things, we should think about it from the point of
view of Python's data model (objects; "is"). But when we talk about
things like "length", "square root", "sum" or "name", the point of view
is the abstractions the objects are standing for ("==").


Interesting. So in your view, a string object representing zero
characters is "an", but its length is "the"? I'd have thought that
both are considered value types, where identity is immaterial.

There can be multiple empty strings, which the implementation _might_ 
optimise to a singleton, but each string has only one length.


A string of length > 1 has multiple characters, each being _a_ 
character, but the string as a whole has only one length, so we can call 
it _the_ length.



Thanks for all the insights, all. This is a curious point of English
and one that I've definitely seen people on both sides of.

My apologies for not responding earlier or to individual posts. For a
while (and I'm actually not certain that this post will make it), all
Gmail addresses have been unable to post to python-list, and even
contacting the list-owner wasn't possible.


--
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Richard Damon
On 7/28/19 7:04 PM, Chris Angelico wrote:
> On Sun, Jul 28, 2019 at 5:36 PM Marko Rauhamaa  wrote:
>> So it depends on the context if the relevant equivalence is "is" or
>> "==". Maybe the rule of thumb is that if we are talking about strings,
>> integers and similar things, we should think about it from the point of
>> view of Python's data model (objects; "is"). But when we talk about
>> things like "length", "square root", "sum" or "name", the point of view
>> is the abstractions the objects are standing for ("==").
> Interesting. So in your view, a string object representing zero
> characters is "an", but its length is "the"? I'd have thought that
> both are considered value types, where identity is immaterial.
>
> Thanks for all the insights, all. This is a curious point of English
> and one that I've definitely seen people on both sides of.
>
> My apologies for not responding earlier or to individual posts. For a
> while (and I'm actually not certain that this post will make it), all
> Gmail addresses have been unable to post to python-list, and even
> contacting the list-owner wasn't possible.
>
> ChrisA

It is the length of a string, as a given string only has a single
length, so grammatically, it wants the definite article always.

When talking of empty strings, we need to look a bit at context.  "The
empty string" implies that there is only one of them, and if we are
talking about values, then there is only one empty string values, so
"The empty string value" would be correct (and the term value might be
implied by context). If we are talking about object, like with the
python word "is", then the empty string is not promised to be a
singleton, so grammatically, it should be "A empty string object", and
again the term object might be implied by the context.

English, being a natural language (and one with a complicated history),
can be filled with all sorts of strangeness, and this can get compounded
when it wants to be harmonized with a technical subject which can't deal
with some of the naturalness of language, thus we can't try to use some
sort of rule matching the type of article to the appropriateness of the
python word "is".

-- 
Richard Damon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Chris Angelico
On Mon, Jul 29, 2019 at 9:48 AM Michael Torrie  wrote:
>
> On 7/28/19 5:55 AM, Jonathan Moules wrote:
> > But this appears to be explicitly called out as being "Worse" in PEP8:
> >
> > """
> > Don't compare boolean values to True or False using ==.
> >
> > Yes:   if greeting:
> > No:if greeting == True:
> > Worse: if greeting is True:
> > """
>
> Yet the recommended solution to the problem of wanting a default
> argument of an empty list is something like this:
>
> def foo(bar=False);
> if bar is False:
> bar = []
>
> 
>
> Clearly in this case the expression "not bar" would be incorrect.

This is a fairly unusual case, though. More commonly, the default
would be None, not False, and "if bar is None:" is extremely well
known and idiomatic.

> There's a difference between looking for a particular identity or
> sentinel, and checking for truthiness or falsiness.
>
> So I guess it all depends on what you need to do. If you just need to
> check truthiness, just do "if greeting"  If you need to know if the
> variable is some particular sentinel, use the "if greeting is whatever".

This analysis is correct, but the situations where you *actually* want
to know if something "is True" or "is False" are rare enough that PEP
8 doesn't need to mention them; whereas the case where you actually
just need the truthiness is so common (and so often miswritten) that
it's worth being clear on it.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Richard Damon
On 7/28/19 11:13 AM, MRAB wrote:
> On 2019-07-28 13:30, Cameron Simpson wrote:
>>
>> The collection is "the things". "all" qualifies it, versus, say, "some
>> of the things" or "the first of the things" etc.
>>
> [snip]
>
> It's strange that "all the things" (meaning "all of the things") is
> OK, but otherwise it's "one of the things", "some of the things", etc.
>
> That's English for you!

My thoughts is that "of" implies membership in some category, some part,
but the phrase "all the things", we aren't looking at any category, but
literally ALL the things. "All of the things" implies all of the things
within some group, possibly implied by context. The category "thing" is
implied by the word thing, so doesn't call for the preposition. Saying
"All of the things" to mean every single one of them implies creating
some category that just happens to include every one of them.

-- 
Richard Damon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Richard Damon
On 7/28/19 7:46 PM, Michael Torrie wrote:
> On 7/28/19 5:55 AM, Jonathan Moules wrote:
>> But this appears to be explicitly called out as being "Worse" in PEP8:
>>
>> """
>> Don't compare boolean values to True or False using ==.
>>
>> Yes:   if greeting:
>> No:    if greeting == True:
>> Worse: if greeting is True:
>> """
> Yet the recommended solution to the problem of wanting a default
> argument of an empty list is something like this:
>
> def foo(bar=False);
> if bar is False:
> bar = []
>
> 
>
> Clearly in this case the expression "not bar" would be incorrect.
>
> There's a difference between looking for a particular identity or
> sentinel, and checking for truthiness or falsiness.
>
> So I guess it all depends on what you need to do. If you just need to
> check truthiness, just do "if greeting"  If you need to know if the
> variable is some particular sentinel, use the "if greeting is whatever".

I thought the recommended value was None, not False (so you don't need
to ask why not True). I suppose if None is a valid value for the input
you would need something else, and False is one possibility.

-- 
Richard Damon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Chris Angelico
On Mon, Jul 29, 2019 at 10:06 AM Richard Damon  wrote:
> When talking of empty strings, we need to look a bit at context.  "The
> empty string" implies that there is only one of them, and if we are
> talking about values, then there is only one empty string values, so
> "The empty string value" would be correct (and the term value might be
> implied by context). If we are talking about object, like with the
> python word "is", then the empty string is not promised to be a
> singleton, so grammatically, it should be "A empty string object", and
> again the term object might be implied by the context.

So I guess the original question can be reworded as:

When you're describing indistinguishable objects, are you really
talking about objects, or are you talking about values?

With numbers, it's pretty obvious that you talk about values. You can
logically say "if the spamminess is zero, blah blah blah" even though
you'd actually say "if spam == 0:" in the code. With strings, is it
therefore logical to say "is the empty string" even though you'd
actually be comparing to see if it "==" another empty string?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Chris Angelico
On Mon, Jul 29, 2019 at 10:15 AM Richard Damon  wrote:
>
> On 7/28/19 7:46 PM, Michael Torrie wrote:
> > On 7/28/19 5:55 AM, Jonathan Moules wrote:
> >> But this appears to be explicitly called out as being "Worse" in PEP8:
> >>
> >> """
> >> Don't compare boolean values to True or False using ==.
> >>
> >> Yes:   if greeting:
> >> No:if greeting == True:
> >> Worse: if greeting is True:
> >> """
> > Yet the recommended solution to the problem of wanting a default
> > argument of an empty list is something like this:
> >
> > def foo(bar=False);
> > if bar is False:
> > bar = []
> >
> > 
> >
> > Clearly in this case the expression "not bar" would be incorrect.
> >
> > There's a difference between looking for a particular identity or
> > sentinel, and checking for truthiness or falsiness.
> >
> > So I guess it all depends on what you need to do. If you just need to
> > check truthiness, just do "if greeting"  If you need to know if the
> > variable is some particular sentinel, use the "if greeting is whatever".
>
> I thought the recommended value was None, not False (so you don't need
> to ask why not True). I suppose if None is a valid value for the input
> you would need something else, and False is one possibility.
>

In that situation, you'd be more likely to use a dedicated sentinel object:

_SENTINEL = object()
def foo(bar=_SENTINEL):
if bar is _SENTINEL: bar = []

But there is a not-too-rare situation where you'd want to check if
something "is False", and that's some form of three-valued logic, eg
"true, false, and unspecified". For instance:

def foo(verbose=None):
if verbose is False:
# caller specifically wanted quiet mode

if verbose is True:
# caller specifically wanted verbose mode

Of course, if the third value can be simplified away (eg None means
"use the global default"), then you can still just use "if verbose is
None:" and then reassign it. But this is a legit reason to use "is
False".

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Richard Damon
On 7/28/19 8:25 PM, Chris Angelico wrote:
> On Mon, Jul 29, 2019 at 10:15 AM Richard Damon  
> wrote:
>> On 7/28/19 7:46 PM, Michael Torrie wrote:
>>> On 7/28/19 5:55 AM, Jonathan Moules wrote:
 But this appears to be explicitly called out as being "Worse" in PEP8:

 """
 Don't compare boolean values to True or False using ==.

 Yes:   if greeting:
 No:if greeting == True:
 Worse: if greeting is True:
 """
>>> Yet the recommended solution to the problem of wanting a default
>>> argument of an empty list is something like this:
>>>
>>> def foo(bar=False);
>>> if bar is False:
>>> bar = []
>>>
>>> 
>>>
>>> Clearly in this case the expression "not bar" would be incorrect.
>>>
>>> There's a difference between looking for a particular identity or
>>> sentinel, and checking for truthiness or falsiness.
>>>
>>> So I guess it all depends on what you need to do. If you just need to
>>> check truthiness, just do "if greeting"  If you need to know if the
>>> variable is some particular sentinel, use the "if greeting is whatever".
>> I thought the recommended value was None, not False (so you don't need
>> to ask why not True). I suppose if None is a valid value for the input
>> you would need something else, and False is one possibility.
>>
> In that situation, you'd be more likely to use a dedicated sentinel object:
>
> _SENTINEL = object()
> def foo(bar=_SENTINEL):
> if bar is _SENTINEL: bar = []
>
> But there is a not-too-rare situation where you'd want to check if
> something "is False", and that's some form of three-valued logic, eg
> "true, false, and unspecified". For instance:
>
> def foo(verbose=None):
> if verbose is False:
> # caller specifically wanted quiet mode
>
> if verbose is True:
> # caller specifically wanted verbose mode
>
> Of course, if the third value can be simplified away (eg None means
> "use the global default"), then you can still just use "if verbose is
> None:" and then reassign it. But this is a legit reason to use "is
> False".
>
> ChrisA

The more common way to handle the 3 value case in my experience is to
first handle the 'special case' (check for None in your example) and
then use the normal truthiness test.

Then you example would be:

def foo(verbose=None):

    if verbose is None:

    # Didn't specify verbosity

    elif verbose:

  # Specified Verbose case

   else:

  # Specified none Verbose case


Do you REALLY mean that foo(0) is to be different than foo(false)?



-- 
Richard Damon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Chris Angelico
On Mon, Jul 29, 2019 at 10:43 AM Richard Damon  wrote:
>
> On 7/28/19 8:25 PM, Chris Angelico wrote:
> > Of course, if the third value can be simplified away (eg None means
> > "use the global default"), then you can still just use "if verbose is
> > None:" and then reassign it. But this is a legit reason to use "is
> > False".
> >
> > ChrisA
>
> The more common way to handle the 3 value case in my experience is to
> first handle the 'special case' (check for None in your example) and
> then use the normal truthiness test.
>

That works fine if you can actually handle the special case first and
dispose of it, but that doesn't always work, and when it doesn't, you
may indeed want to specify "is False" or "is True".

Chris
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Grant Edwards
On 2019-07-29, Richard Damon  wrote:
> On 7/28/19 7:46 PM, Michael Torrie wrote:

>> Yet the recommended solution to the problem of wanting a default
>> argument of an empty list is something like this:
>>
>> def foo(bar=False);
>> if bar is False:
>> bar = []
>>
>> 
>
> I thought the recommended value was None, not False (so you don't need
> to ask why not True). I suppose if None is a valid value for the input
> you would need something else, and False is one possibility.

Yes 'None' is definitely the normal idiom, and everybody will know
what you're doing.  If you use False, people are going to be confused.

def foo(bar=None)
   if bar is None
   bar = []
   ...




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Richard Damon
On 7/28/19 8:46 PM, Chris Angelico wrote:
> On Mon, Jul 29, 2019 at 10:43 AM Richard Damon  
> wrote:
>> On 7/28/19 8:25 PM, Chris Angelico wrote:
>>> Of course, if the third value can be simplified away (eg None means
>>> "use the global default"), then you can still just use "if verbose is
>>> None:" and then reassign it. But this is a legit reason to use "is
>>> False".
>>>
>>> ChrisA
>> The more common way to handle the 3 value case in my experience is to
>> first handle the 'special case' (check for None in your example) and
>> then use the normal truthiness test.
>>
> That works fine if you can actually handle the special case first and
> dispose of it, but that doesn't always work, and when it doesn't, you
> may indeed want to specify "is False" or "is True".
>
> Chris

If you can't handle it first (or really at the same time)


def foo(verbose=None):
    if verbose is not None:
    if verbose:
  # Specified Verbose case
   else:
  # Specified none Verbose case

which is really the same as before if you left the Not Specified case empty.

Again, the question is do really need to force the giving of a bool, or can you 
deal with a truthy/falsey/None value? (which may just require a bool call at 
the call site, with some code to possibly handle the None case. 

-- 
Richard Damon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Michael Torrie
On 7/28/19 6:04 PM, Chris Angelico wrote:
> This is a fairly unusual case, though. More commonly, the default
> would be None, not False, and "if bar is None:" is extremely well
> known and idiomatic.

Ahh yes, true.

> This analysis is correct, but the situations where you *actually* want
> to know if something "is True" or "is False" are rare enough that PEP
> 8 doesn't need to mention them; whereas the case where you actually
> just need the truthiness is so common (and so often miswritten) that
> it's worth being clear on it.

It may well be that a distinct sentinel object is preferred to True or
False in the majority of cases.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Boolean comparison & PEP8

2019-07-28 Thread Terry Reedy

On 7/28/2019 7:55 AM, Jonathan Moules wrote:


Lets say I want to know if the value of `x` is bool(True).
My preferred way to do it is:

if x is True:
     pass


If you know that expression x is boolean, and one usually knows or 
should know whether is it or is not, '= True' and 'is True' and 
similarly for False are redundant.  Why not 'if x is True is True' and 
so on.



Because this tests both the value and the type.


See below.

Newbies *have* written things like 'if (x == 3) is True' and this is 
what prompted this entry in PEP 8.



"""
Don't compare boolean values to True or False using ==.

Yes:   if greeting:
No:    if greeting == True:
Worse: if greeting is True:
"""


If `x` can also have a value of "1"(str) or 1(int) 


Have you run across any stdlib function that returns such a mixture of 
types?  Remember that PEP 8 is specifically a style guide for stdlib code.


--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Cameron Simpson

On 28Jul2019 20:11, Richard Damon  wrote:

On 7/28/19 11:13 AM, MRAB wrote:

On 2019-07-28 13:30, Cameron Simpson wrote:
The collection is "the things". "all" qualifies it, versus, say, 
"some of the things" or "the first of the things" etc.



[snip]
It's strange that "all the things" (meaning "all of the things") is
OK, but otherwise it's "one of the things", "some of the things", etc.

That's English for you!


Well, we also say "one thing", synonymous with "a thing" and "some 
things". Also "some thing" synonymous with "a thing" and "something" 
meaning an arbitrary context dependent thing, but not necessarily one of 
the "thing"s we might otherwise have been talking about.


On reflection, "the things" is a definite group, and "some of the 
things" or "one of the things" is a subset/member of that group. Whereas 
"something" or "some things" is usually vaguer, where you don't have a 
defined group of things but your are talking about things in a context.



My thoughts is that "of" implies membership in some category, some part,
but the phrase "all the things", we aren't looking at any category, but
literally ALL the things. "All of the things" implies all of the things
within some group, possibly implied by context. The category "thing" is
implied by the word thing, so doesn't call for the preposition. Saying
"All of the things" to mean every single one of them implies creating
some category that just happens to include every one of them.


I think I'm saying what you're saying here.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-28 Thread Cameron Simpson

On 29Jul2019 10:15, Chris Angelico  wrote:

On Mon, Jul 29, 2019 at 10:06 AM Richard Damon  wrote:

When talking of empty strings, we need to look a bit at context.  "The
empty string" implies that there is only one of them, and if we are
talking about values, then there is only one empty string values, so
"The empty string value" would be correct (and the term value might be
implied by context). If we are talking about object, like with the
python word "is", then the empty string is not promised to be a
singleton, so grammatically, it should be "A empty string object", and
again the term object might be implied by the context.


So I guess the original question can be reworded as:

When you're describing indistinguishable objects, are you really
talking about objects, or are you talking about values?

With numbers, it's pretty obvious that you talk about values. You can
logically say "if the spamminess is zero, blah blah blah" even though
you'd actually say "if spam == 0:" in the code. With strings, is it
therefore logical to say "is the empty string" even though you'd
actually be comparing to see if it "==" another empty string?


I wouldn't be saying "the empty string". I'd being describing the 
string: "if the string is empty", "if s is an empty string", etc. So 
values again.


I think the wish to use the phrasing "the empty string" either comes 
from an implied metaphorthat assumes deduped immutable objects or from a 
mathematical background where eg in set theory one talks about "the 
empty set". Someone else posted a better description of the methematical 
context, where "the empty set" is effectively naming a category of sets 
(those of size 0) and considering that a single thing in that context.


I'm for running with "values" in the example you started with. I think 
the "the empty string" is mathematical context specific terminology 
leaking into the wrong domain.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list