Added the pocoo styleguide to the documentation
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent e84ca8e · Browse files · 2 files·+201 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+201 added−0 removed
- other:+201 added−0 removed
Provenance
- Commit
793a56b- Tree
d28329f- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
e84ca8e
2 files changed+201 added−0 removed
modified:docs/contents.rst.inc+1 added
42 unmodified lines43 htmlfaq44 security45 unicode46 extensiondev47+ styleguide48 upgrading49 changelog50 licenseadded:docs/styleguide.rst+200 added
1+Pocoo Styleguide2+================3+4+The Pocoo styleguide is the styleguide for all Pocoo Projects, including5+Flask. This styleguide is a requirement for Patches to Flask and a6+recommendation for Flask extensions.7+8+In general the Pocoo Styleguide closely follows :pep:`8` with some small9+differences and extensions.10+11+General Layout12+--------------13+14+Indentation:15+ 4 real spaces. No tabs, no exceptions.16+17+Maximum line length:18+ 79 characters with a soft limit for 84 if absolutely necessary. Try19+ to avoid too nested code by cleverly placing `break`, `continue` and20+ `return` statements.21+22+Continuing long statements:23+ To continue a statement you can use backslashes in which case you should24+ align the next line with the last dot or equal sign, or indent four25+ spaces::26+27+ this_is_a_very_long(function_call, 'with many parameters') \28+ .that_returns_an_object_with_an_attribute29+30+ MyModel.query.filter(MyModel.scalar > 120) \31+ .order_by(MyModel.name.desc()) \32+ .limit(10)33+34+ If you break in a statement with parentheses or brances, align to the35+ braces::36+37+ this_is_a_very_long(function_call, 'with many parameters',38+ 23, 42, 'and even more')39+40+ For lists or tuples with many items, break immediately after the41+ opening brace::42+43+ items = [44+ 'this is the first', 'set of items', 'with more items',45+ 'to come in this line', 'like this'46+ ]47+48+Blank lines:49+ Top level functions and classes are separated by two lines, everything50+ else by one. Do not use too many blank lines to separate logical51+ segments in code. Example::52+53+ def hello(name):54+ print 'Hello %s!' % name55+56+57+ def goodbye(name):58+ print 'See you %s.' % name59+60+61+ class MyClass(object):62+ """This is a simple docstring"""63+64+ def __init__(self, name):65+ self.name = name66+67+ def get_annoying_name(self):68+ return self.name.upper() + '!!!!111'69+70+Expressions and Statements71+--------------------------72+73+General whitespace rules:74+ - Whitespace is absend for unary operators that are not works75+ (eg: ``-``, ``~`` etc.) as well on the inner side of parentheses.76+ - Whitespace is placed between binary operators.77+78+ Good::79+80+ exp = -1.0581+ value = (item_value / item_count) * offset / exp82+ value = my_list[index]83+ value = my_dict['key']84+85+ Bad::86+87+ exp = - 1.0588+ value = ( item_value / item_count ) * offset / exp89+ value = (item_value/item_count)*offset/exp90+ value=( item_value/item_count ) * offset/exp91+ value = my_list[ index ]92+ value = my_dict ['key']93+94+Yoda statements are a nogo:95+ Never compare constant with variable, always variable with constant:96+97+ Good::98+99+ if method == 'md5':100+ pass101+102+ Bad::103+104+ if 'md5' == method:105+ pass106+107+Comparisons:108+ - against arbitary types: ``==`` and ``!=``109+ - against singletones with ``is`` and ``is not`` (eg: ``foo is not110+ None``)111+ - never compare something with `True` or `False` (for example never112+ do ``foo == False``, do ``not foo`` instead)113+114+Negated containment checks:115+ use ``foo not in bar`` instead of ``not foo in bar``116+117+Instance checks:118+ ``isinstance(a, C)`` instead of ``type(A) is C``, but try to avoid119+ instance checks in general. Check for features.120+121+122+Naming Conventions123+------------------124+125+- Class names: ``CamelCase``, with acronyms kept uppercase (``HTTPWriter``126+ and not ``HttpWriter``)127+- Variable names: ``lowercase_with_underscores``128+- Method and functin names: ``lowercase_with_underscores``129+- Constants: ``UPPERCASE_WITH_UNDERSCORES``130+- precompiled regular expressions: ``name_re``131+132+Protected members are prefixed with a single underscore. Double133+underscores are reserved for mixin classes.134+135+On classes with keywords, trailing underscores are appended. Clashes with136+builtins are allowed and **must not** be resolved by appending an137+underline to the variable name. If the function needs to access a138+shadowed builtin, rebind the builtin to a different name instead.139+140+Function and method arguments:141+ - class methods: ``cls`` as first parameter142+ - instance methods: ``self`` as first parameter143+ - lambdas for properties might have the first parameter replaced144+ with ``x`` like in ``display_name = property(lambda x: x.real_name145+ or x.username)``146+147+148+Docstrings149+----------150+151+Docstring conventions:152+ All docstrings are formatted with reStructuredText as understood by153+ Sphinx. Depending on the number of lines in the docstring, they are154+ layed out differently. If it's just one line, the closing tripple155+ quote is on the same line as the opening, otherwise the text is on156+ the same line as the opening quote and the tripple quote that closes157+ the string on its own line::158+159+ def foo():160+ """This is a simple docstring"""161+162+163+ def bar():164+ """This is a longer docstring with so much information in there165+ that it spans three lines. In this case the closing tripple quote166+ is on its own line.167+ """168+169+Module header:170+ The module header consists of an utf-8 encoding declaration (if non171+ ASCII letters are used, but it is recommended all the time) and a172+ standard docstring::173+174+ # -*- coding: utf-8 -*-175+ """176+ package.module177+ ~~~~~~~~~~~~~~178+179+ A brief description goes here.180+181+ :copyright: (c) YEAR by AUTHOR.182+ :license: LICENSE_NAME, see LICENSE_FILE for more details.183+ """184+185+ Please keep in mind that proper copyrights and license files are a186+ requirement for approved Flask extensions.187+188+189+Comments190+--------191+192+Rules for comments are similar to docstrings. Both are formatted with193+reStructuredText. If a comment is used to document an attribute, put a194+colon after the opening pound sign (``#``)::195+196+ class User(object):197+ #: the name of the user as unicode string198+ name = Column(String)199+ #: the sha1 hash of the password + inline salt200+ pw_hash = Column(String)