PEP 8 coding style included in grammar ?

I was wondering why the PEP coding style ( https://www.python.org/dev/peps/pep-0008/) is not natively included in python grammar ? For instance, both, *function definition* and *class definition*, are using the same “NAME” token. ((see, https://docs.python.org/3/reference/grammar.html). classdef: 'class' NAME ['(' [arglist] ')'] ':' suite funcdef: 'def' NAME parameters ['->' test] ':' suite Then, we are using libraries like pyflake, flake8, pylint, to check the coding style. It seems useful to natively make distinction between NAME of classdef and NAME of funcdef, with something like: classdef: 'class' NAME_CLASS ['(' [arglist] ')'] ':' suite funcdef: 'def' NAME_FUNC parameters ['->' test] ':' suite NAME_CLASS: · Class name should normally use the CapWord convention; NAME_FUNC: · Function name should be lowercase, with words separated by underscore as necessary to improve readability, · mixedCase is allowed; STYLE_CAP_WORDS = r’([A-Z]{1}[a-z]+(_[A-Z]{1}[a-z]+)*)’ STYLE_UNDERSCORE_LOW_WORDS = r’([a-z]+(_[a-z]+)*)’ STYLE_MIXED_CASE = r’([a-z]{1,}([A-Z]{1}[a-z]+)*’) NAME_FUNC = STYLE_LOW_WORDS | STYLE_UNDERSCORE_LOW_WORDS | STYLE_MIXED_CASE NAME_CLASS = STYLE_CAP_WORDS | NAME_FUNC # naming convention for functions may be used in cases where the interface is documented and used primarily as a callable (pep8 source). I didn't find any information about this point in a previous post or elsewhere. Is there any reason for such a choice ? or is it a dark old discussion we never talk about ? Mathieu ------------- import re # Testing the first part of the class def, only. style_cap_words = r'^class ([A-Z]{1}[a-z]+(_?[A-Z]{1}[a-z]+)*)$' compiled_style_cap_words = re.compile(style_cap_words) status_samples = {True:['class Hello', 'class Hel_Lo', # ok if Hel and Lo are 2 words 'class HelLo', # same. ], False:['class HellO', 'class _He', 'class HEllo', 'class HE', 'class H', 'class h', 'class Hell_oo', 'class Hell_', 'class _hell', 'class H_E_L_L_O', 'class _H']} def is_matched(sample, pattern=compiled_style_cap_words): matched = pattern.match(sample) return matched is not None for status, samples in status_samples.items(): for sample in samples: is_correct = status == is_matched(sample) assert is_correct, '%s is not correct, required %s' % (sample, status)

Of course, in Python 8 this naming convention will indeed be enforced. https://mail.python.org/pipermail/python-dev/2016-March/143603.html Op 1 mrt. 2017 15:16 schreef "Alexandre Brault" <abrault@mapgears.com>:

On Thu, Mar 2, 2017 at 11:04 AM, Barry Warsaw <barry@python.org> wrote:
Also, the grammar has a much stricter backward compatibility guarantee than any style guide ever can (or should). After some discussion about this and related topics on python-list, I posted this collection: http://rosuav.blogspot.com/2016/04/falsehoods-programmers-believe-about.html ChrisA

On 02.03.2017 01:04, Barry Warsaw wrote:
... plus PEP 8 is a style guide, not a fixed set of rules. You are free to extend it, mix and match it, to suit your own needs. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Mar 02 2017)
::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/

Of course, in Python 8 this naming convention will indeed be enforced. https://mail.python.org/pipermail/python-dev/2016-March/143603.html Op 1 mrt. 2017 15:16 schreef "Alexandre Brault" <abrault@mapgears.com>:

On Thu, Mar 2, 2017 at 11:04 AM, Barry Warsaw <barry@python.org> wrote:
Also, the grammar has a much stricter backward compatibility guarantee than any style guide ever can (or should). After some discussion about this and related topics on python-list, I posted this collection: http://rosuav.blogspot.com/2016/04/falsehoods-programmers-believe-about.html ChrisA

On 02.03.2017 01:04, Barry Warsaw wrote:
... plus PEP 8 is a style guide, not a fixed set of rules. You are free to extend it, mix and match it, to suit your own needs. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Mar 02 2017)
::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/
participants (6)
-
Alexandre Brault
-
Barry Warsaw
-
Chris Angelico
-
M.-A. Lemburg
-
Mathieu BEAL
-
Stephan Houben