[Python-ideas] [PEP8] Predicate consistency

Marco Buttu marco.buttu at gmail.com
Fri Feb 6 07:21:42 CET 2015


On 06/02/2015 01:12, Barry Warsaw wrote:
> On Feb 05, 2015, at 11:36 PM, Marco Buttu wrote:
>
>> >Hi all, the PEP 8 says that function and method names should be lowercase,
>> >with words separated by underscores as necessary to improve
>> >readability. Maybe it could be a good idea to specify in the PEP8 that the
>> >predicates should not be separated by underscores, because it is pretty
>> >annoying to see this kind of inconsistency:
>> >
>> >     str.isdigit()
>> >     float.is_integer()
> I don't think PEP 8 should change.  Even words in predicates should be
> separated by an underscore.

Are you proposing to change our mind? Because currently we have both in 
the core and in the standard library mainly predicates *not* separated 
by underscores:

isinstance()
issubclass()
hasattr()
str.is*
set.is*
bytearray.is*
math.is*
os.is*
...

And recently: asyncio.iscoroutinefunction(). Your proposal seems to me 
really inconsistent with the whole codebase, and I think the reason 
sometime we get wrong (as in the case of float.is_integer()) is a lack 
(about predicates) in the PEP8. The PEP8 suggests that we should use 
"words separated by underscores as necessary to improve readability", 
and that's why sometimes we write is_foo() instead of isfoo(). I believe 
your suggestion is an evidence of that lack.

So, I am proposing to be more clear, maybe by writing somethink like that:

"""
Function names should be lowercase and, except for predicates, with 
words separated by underscores as necessary to improve readability.
Yes:

# Do not use underscores in predicates
isinstance()
hasattr()
# Use underscores to improve readability
dont_write_bytecode()

No:

is_instance()
has_attr()
dontwritebytecode()
"""

We have to change just this part of the PEP8, because the method section 
says to use the function naming rules.

> But it's not worth it to go back and change old APIs that have been in existence forever.

I am not so crazy ;) I am just proposing a clear rule for predicates in 
order to avoid, _in the future_, inconsistency with the current general 
rule.

-- 
Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbuttu at oa-cagliari.inaf.it



More information about the Python-ideas mailing list