magnum/HACKING.rst
houming-wang 98875345c2 Performance: leverage dict comprehension in PEP-0274
PEP-0274 introduced dict comprehensions to replace dict constructor
with a sequence of length-2 sequences, these are benefits copied
from [1]:
  The dictionary constructor approach has two distinct disadvantages
  from the proposed syntax though.  First, it isn't as legible as a
  dict comprehension.  Second, it forces the programmer to create an
  in-core list object first, which could be expensive.
Magnum does not support python 2.6, we can leverage this.
There is deep dive about PEP-0274[2] and basic tests about
performance[3].
Note: This commit doesn't handle dict constructor with kwagrs.
This commit also adds a hacking rule.

[1]http://legacy.python.org/dev/peps/pep-0274/
[2]http://doughellmann.com/2012/11/12/the-performance-impact-of-using
-dict-instead-of-in-cpython-2-7-2.html
[3]http://paste.openstack.org/show/480757/

Change-Id: I61992fa428d6760449afe3754b02506336e8b421
2015-12-03 22:02:02 -05:00

1.1 KiB

Magnum Style Commandments

Magnum Specific Commandments

  • [M301] policy.enforce_wsgi decorator must be the first decorator on a method.
  • [M310] timeutils.utcnow() wrapper must be used instead of direct calls to datetime.datetime.utcnow() to make it easy to override its return value.
  • [M318] Change assertEqual(A, None) or assertEqual(None, A) by optimal assert like assertIsNone(A)
  • [M322] Method's default argument shouldn't be mutable.
  • [M323] Change assertEqual(True, A) or assertEqual(False, A) by optimal assert like assertTrue(A) or assertFalse(A)
  • [M302] Change assertEqual(A is not None) by optimal assert like assertIsNotNone(A).
  • [M316] Change assertTrue(isinstance(A, B)) by optimal assert like assertIsInstance(A, B).
  • [M334] Change assertTrue/False(A in/not in B, message) to the more specific assertIn/NotIn(A, B, message)
  • [M336] Must use a dict comprehension instead of a dict constructor with a sequence of key-value pairs.