From 2590fb724fe26d262cf99a3370297f4cb68a55ca Mon Sep 17 00:00:00 2001 From: Kyle Date: Wed, 31 Jul 2019 09:03:51 +0900 Subject: [PATCH] Requested changes --- CONTRIBUTING.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 872e4460c..1813f5473 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -368,18 +368,16 @@ view_count = int_or_none(video.get('views')) ### Inline values - Always inline values. +Extracting variables is acceptable for reducing code duplication and improving readability of complex expressions. However, you should avoid extracting variables used only once and moving them to opposite parts of the extractor file, which makes reading the linear flow difficult. #### Example -A good rule of thumb is not to create variables that will only be used once. - Correct: ```python return self.playlist_result( [self._parse_brightcove_metadata(vid, vid.get('id'), headers) - for vid in json_data.get('videos', []) if vid.get('id')], + for vid in json_data.get('videos', []) if vid.get('id')], json_data.get('id'), json_data.get('name'), json_data.get('description')) ``` @@ -387,15 +385,12 @@ return self.playlist_result( Incorrect: ```python -playlist_vids = json_data.get('videos', []) -playlist_id = json_data.get('id') -playlist_title = json_data.get('name') -playlist_description = json_data.get('description') +id = json_data.get('id') return self.playlist_result( [self._parse_brightcove_metadata(vid, vid.get('id'), headers) - for vid in playlist_vids if vid.get('id')], - playlist_id, playlist_title, playlist_description) + for vid in json_data.get('videos', []) if vid.get('id')], + id, json_data.get('name'), json_data.get('description')) ``` ### Collapse fallbacks