2012-02-06 20:43:24 +00:00
|
|
|
Keystone Style Commandments
|
|
|
|
===========================
|
|
|
|
|
2013-11-11 11:10:50 -08:00
|
|
|
- Step 1: Read the OpenStack Style Commandments
|
|
|
|
http://docs.openstack.org/developer/hacking/
|
|
|
|
- Step 2: Read on
|
2012-02-06 20:43:24 +00:00
|
|
|
|
2013-11-11 11:10:50 -08:00
|
|
|
Keystone Specific Commandments
|
|
|
|
------------------------------
|
2012-02-06 20:43:24 +00:00
|
|
|
|
2012-08-29 03:57:15 -05:00
|
|
|
- Avoid using "double quotes" where you can reasonably use 'single quotes'
|
2012-02-06 20:43:24 +00:00
|
|
|
|
2012-03-14 14:28:04 -05:00
|
|
|
|
2012-02-06 20:43:24 +00:00
|
|
|
TODO vs FIXME
|
|
|
|
-------------
|
|
|
|
|
|
|
|
- TODO(name): implies that something should be done (cleanup, refactoring,
|
|
|
|
etc), but is expected to be functional.
|
|
|
|
- FIXME(name): implies that the method/function/etc shouldn't be used until
|
|
|
|
that code is resolved and bug fixed.
|
|
|
|
|
2012-08-29 03:57:15 -05:00
|
|
|
|
2012-03-14 14:28:04 -05:00
|
|
|
Logging
|
|
|
|
-------
|
|
|
|
|
2013-08-19 11:26:35 -05:00
|
|
|
Use the common logging module, and ensure you ``getLogger``::
|
2012-03-14 14:28:04 -05:00
|
|
|
|
2015-02-03 17:05:10 -05:00
|
|
|
from oslo_log import log
|
2012-03-14 14:28:04 -05:00
|
|
|
|
2014-01-01 15:48:32 -08:00
|
|
|
LOG = log.getLogger(__name__)
|
2012-03-14 14:28:04 -05:00
|
|
|
|
|
|
|
LOG.debug('Foobar')
|
2014-02-26 00:17:00 +09:00
|
|
|
|
|
|
|
|
|
|
|
AssertEqual argument order
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
assertEqual method's arguments should be in ('expected', 'actual') order.
|
2014-07-03 13:59:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
Properly Calling Callables
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
Methods, functions and classes can specify optional parameters (with default
|
|
|
|
values) using Python's keyword arg syntax. When providing a value to such a
|
|
|
|
callable we prefer that the call also uses keyword arg syntax. For example::
|
|
|
|
|
|
|
|
def f(required, optional=None):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# GOOD
|
|
|
|
f(0, optional=True)
|
|
|
|
|
|
|
|
# BAD
|
|
|
|
f(0, True)
|
|
|
|
|
|
|
|
This gives us the flexibility to re-order arguments and more importantly
|
|
|
|
to add new required arguments. It's also more explicit and easier to read.
|