From de3edc1b092b4560f9f0b254cf58d6809bc8d6cc Mon Sep 17 00:00:00 2001 From: zooko <> Date: Fri, 10 Oct 2014 15:57:56 +0000 Subject: [PATCH] add `athing in adict` [Imported from Trac: page CodingStandards, version 30] --- CodingStandards.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CodingStandards.md b/CodingStandards.md index 32602e0..6976181 100644 --- a/CodingStandards.md +++ b/CodingStandards.md @@ -43,6 +43,10 @@ from allmydata.util.assertutil import _assert, precondition, postcondition * Don't use the literals `True` or `False` in conditional expressions -- instead just write the expression which will evaluate to true or false. For example, write `if expr:` instead of `if expr == True:` and `if not expr:` instead of `if expr == False:`. * Avoid relying on the fact that empty sequences, empty strings, empty dicts, `0`, and `None` are treated as false. Write `if len(items) == 0:`, `if thing is None:`, etc. +### Miscellaneous + + * `athing in adict.keys()` can be replaced by `athing in adict`, which evaluates to the same boolean result, but is more succinct and more efficient at run-time. + ## Idioms ### Preconditions and Assertions @@ -164,8 +168,6 @@ class BlockStore: self.maintainertype = maintainertype self.backendtype = backendtype ``` -. - ## Official Python Standards