[Python-ideas] [PEP8] Predicate consistency
Andrew Barnert
abarnert at yahoo.com
Fri Feb 6 07:45:15 CET 2015
On Feb 5, 2015, at 22:21, Marco Buttu <marco.buttu at gmail.com> wrote:
> 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,
The PEP already says, right in the existing sentence you quoted, "as necessary to improve readability", not "always". It's not necessary in "isnan".
Elsewhere the PEP talks about consistency with related code. If "isnan" is documented to do effectively the same as the C function of the same name it makes sense to use the same name. That's presumably also why "inspect.isgeneratorfunction" doesn't use underscores--they're arguably necessary, but consistency with "isfunction" trumps that.
Of course it's a judgment call in borderline cases, but that's true for most of PEP 8, and it's not a problem.
Also, are you sure it's really "predicate" that's the relevant difference, as opposed to, say, "short word and really short word" (which is really just a special case of "not necessary for readability").
You use "dont_write_bytecode" as an example of something that obviously needs the underscores. I think the parallel predicate looks better as "doesnt_write_bytecode" than "doesntwritebytecode" (although actually, I'd try to avoid both "don't" and "doesn't" because of the apostrophes...).
And beyond your own example, "is_greater_than_one" or "can_fit_on_filesystem" seem like they need underscores, while "dotwice" seems fine without.
More information about the Python-ideas
mailing list