From 1f2469b09f576bd591293578794619e6a74109b7 Mon Sep 17 00:00:00 2001 From: Gerald Britton Date: Thu, 21 Jan 2010 18:42:53 +0000 Subject: [PATCH] Simplify with built-in functions where possible. e.g. change [x for x in y if x] to filter(None, y) change [f(x) for x in y] to map(f, x) change [x for x in y] to list(y) These changes reduce source code size and complexity and produce some minor performance gains svn: r14104 --- src/Filters/Rules/Place/_HasPlace.py | 2 +- src/GrampsLogger/_RotateHandler.py | 4 ++-- src/ScratchPad.py | 3 +-- src/Simple/_SimpleAccess.py | 2 +- src/Simple/_SimpleTable.py | 2 +- src/UndoHistory.py | 2 +- src/Utils.py | 10 +++++----- src/docgen/TextBufDoc.py | 2 +- src/gen/db/base.py | 2 +- src/gen/lib/addressbase.py | 7 ++----- src/gen/lib/attrbase.py | 2 +- src/gen/lib/family.py | 2 +- src/gen/lib/ldsordbase.py | 2 +- src/gen/lib/mediabase.py | 8 ++------ src/gen/lib/notebase.py | 8 ++------ src/gen/lib/person.py | 2 +- src/gen/lib/src.py | 2 +- src/gen/lib/srcbase.py | 8 +++----- src/gen/lib/urlbase.py | 8 ++------ src/gen/proxy/private.py | 2 +- src/gui/editors/editfamily.py | 4 ++-- src/gui/pluginmanager.py | 6 ++---- src/gui/views/treemodels/familymodel.py | 4 ++-- src/plugins/export/ExportGedcom.py | 2 +- src/plugins/gramplet/AgeStats.py | 6 +++--- src/plugins/gramplet/FanChartGramplet.py | 2 +- src/plugins/import/ImportGrdb.py | 2 +- src/plugins/import/ImportProGen.py | 24 ++++++++++++------------ src/plugins/lib/libgrdb.py | 4 ++-- src/plugins/tool/ChangeNames.py | 2 +- src/plugins/tool/ExtractCity.py | 2 +- src/plugins/tool/PatchNames.py | 2 +- src/plugins/tool/RemoveUnused.py | 2 +- src/plugins/tool/Verify.py | 4 ++-- src/plugins/view/fanchartview.py | 2 +- src/web/libdjango.py | 12 ++++++------ src/web/utils.py | 2 +- test/GrampsDb/GrampsDbBase_Test.py | 20 ++++++++++---------- 38 files changed, 81 insertions(+), 101 deletions(-) diff --git a/src/Filters/Rules/Place/_HasPlace.py b/src/Filters/Rules/Place/_HasPlace.py index 6e7fc9c6b..6dd4c42e7 100644 --- a/src/Filters/Rules/Place/_HasPlace.py +++ b/src/Filters/Rules/Place/_HasPlace.py @@ -62,7 +62,7 @@ class HasPlace(Rule): return False # If no location data was given then we're done: match - if not [item for item in self.list[1:] if item]: + if not any(self.list[1:]): return True # Something was given, so checking for location until we match diff --git a/src/GrampsLogger/_RotateHandler.py b/src/GrampsLogger/_RotateHandler.py index 128b863ad..836a81697 100644 --- a/src/GrampsLogger/_RotateHandler.py +++ b/src/GrampsLogger/_RotateHandler.py @@ -28,8 +28,8 @@ class RotateHandler(logging.Handler): Return the buffer with the records in the correct order. """ - return [record for record in self._buffer[self._index:] + self._buffer[:self._index] - if record is not None] + return filter(None, + self._buffer[self._index:] + self._buffer[:self._index]) def get_formatted_log(self, remove_tail_duplicate=None): """ diff --git a/src/ScratchPad.py b/src/ScratchPad.py index a949ce373..d2067dcd2 100644 --- a/src/ScratchPad.py +++ b/src/ScratchPad.py @@ -472,8 +472,7 @@ class ScratchPadSourceRef(ScratchPadGrampsTypeWrapper): base = self._db.get_source_from_handle(self._obj.get_reference_handle()) self._title = base.get_title() - notelist = [ self._db.get_note_from_handle(hndl) - for hndl in self._obj.get_note_list() ] + notelist = map(self._db.get_note_from_handle, self._obj.get_note_list()) srctxtlist = [ note for note in notelist if note.get_type() == gen.lib.NoteType.SOURCE_TEXT] diff --git a/src/Simple/_SimpleAccess.py b/src/Simple/_SimpleAccess.py index d9af95eb3..284c897d0 100644 --- a/src/Simple/_SimpleAccess.py +++ b/src/Simple/_SimpleAccess.py @@ -683,7 +683,7 @@ class SimpleAccess(object): if obj: handles = [ ref.ref for ref in obj.get_source_references() ] - return [ self.dbase.get_source_from_handle(h) for h in handles ] + return map(self.dbase.get_source_from_handle, handles) else: return [] diff --git a/src/Simple/_SimpleTable.py b/src/Simple/_SimpleTable.py index 2ea093e3d..f72262f4f 100644 --- a/src/Simple/_SimpleTable.py +++ b/src/Simple/_SimpleTable.py @@ -100,7 +100,7 @@ class SimpleTable(object): columns.append(col) # end of unicode fix self.__columns = list(copy.copy(columns)) - self.__sort_vals = [[] for i in range(len(self.__columns))] + self.__sort_vals = [[]]*len(self.__columns) def set_callback(self, which, callback): """ diff --git a/src/UndoHistory.py b/src/UndoHistory.py index 9c8c15ea4..f14a6600c 100644 --- a/src/UndoHistory.py +++ b/src/UndoHistory.py @@ -221,7 +221,7 @@ class UndoHistory(ManagedWindow.ManagedWindow): self.model.append(row=[time_text,mod_text,fg,bg]) # Get the not-None portion of transaction list - translist = [item for item in self.undodb.translist if item] + translist = filter(None, self.undodb.translist) for transaction in translist: time_text = time.ctime(transaction.timestamp) mod_text = transaction.get_description() diff --git a/src/Utils.py b/src/Utils.py index 5ad72205a..9a0de79d0 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -1103,7 +1103,7 @@ def get_referents(handle, db, primary_objects): """ # Use one pass through the reference map to grab all the references - object_list = [item for item in db.find_backlink_handles(handle)] + object_list = db.find_backlink_handles(handle) # Then form the object-specific lists the_lists = () @@ -1267,8 +1267,8 @@ def relative_path(original, base): target_list = (orig_name).split(os.sep) # make sure '/home/person' and 'c:/home/person' both give # list ['home', 'person'] - base_list = [word for word in base_list if word] - target_list = [word for word in target_list if word] + base_list = filter(None, base_list) + target_list = filter(None, target_list) i = -1 for i in range(min(len(base_list), len(target_list))): if base_list[i] <> target_list[i]: break @@ -1419,8 +1419,8 @@ def get_participant_from_event(db, event_handle): """ participant = "" ellipses = False - result_list = [i for i in db.find_backlink_handles(event_handle, - include_classes=['Person', 'Family'])] + result_list = list(db.find_backlink_handles(event_handle, + include_classes=['Person', 'Family'])) #obtain handles without duplicates people = set([x[1] for x in result_list if x[0] == 'Person']) families = set([x[1] for x in result_list if x[0] == 'Family']) diff --git a/src/docgen/TextBufDoc.py b/src/docgen/TextBufDoc.py index 1297314c6..0494911c0 100644 --- a/src/docgen/TextBufDoc.py +++ b/src/docgen/TextBufDoc.py @@ -149,7 +149,7 @@ class TextBufDoc(BaseDoc, TextDoc): tab_array = pango.TabArray(len(new_tabs)+1,True) index = 0 - for tab in [ pixels(x) for x in new_tabs ]: + for tab in map(pixels, new_tabs): tab_array.set_tab(index, pango.TAB_LEFT, tab) index += 1 tag.set_property("tabs", tab_array) diff --git a/src/gen/db/base.py b/src/gen/db/base.py index f981fe376..ee4e12834 100644 --- a/src/gen/db/base.py +++ b/src/gen/db/base.py @@ -1601,7 +1601,7 @@ class DbWriteBase(object): self.set_default_person_handle(None) # loop through the family list - for family_handle in [ f for f in person.get_family_handle_list() if f ]: + for family_handle in filter(None, person.get_family_handle_list()): family = self.get_family_from_handle(family_handle) diff --git a/src/gen/lib/addressbase.py b/src/gen/lib/addressbase.py index 74b561eaa..03c2bf59c 100644 --- a/src/gen/lib/addressbase.py +++ b/src/gen/lib/addressbase.py @@ -51,10 +51,7 @@ class AddressBase(object): :param source: Object used to initialize the new object :type source: AddressBase """ - if source: - self.address_list = [Address(addr) for addr in source.address_list] - else: - self.address_list = [] + self.address_list = map(Address, source.address_list) if source else [] def serialize(self): """ @@ -66,7 +63,7 @@ class AddressBase(object): """ Convert a serialized tuple of data to an object. """ - self.address_list = [Address().unserialize(item) for item in data] + self.address_list = map(Address().unserialize, data) def add_address(self, address): """ diff --git a/src/gen/lib/attrbase.py b/src/gen/lib/attrbase.py index c7cb06a67..b5ccbd3a7 100644 --- a/src/gen/lib/attrbase.py +++ b/src/gen/lib/attrbase.py @@ -67,7 +67,7 @@ class AttributeBase(object): """ Convert a serialized tuple of data to an object. """ - self.attribute_list = [Attribute().unserialize(item) for item in data] + self.attribute_list = map(Attribute().unserialize, data) def add_attribute(self, attribute): """ diff --git a/src/gen/lib/family.py b/src/gen/lib/family.py index 9b699d88f..5dfb49d84 100644 --- a/src/gen/lib/family.py +++ b/src/gen/lib/family.py @@ -241,7 +241,7 @@ class Family(SourceBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase, :returns: Returns the list of child objects that may carry textual data. :rtype: list """ - add_list = [item for item in self.lds_ord_list if item] + add_list = filter(None, self.lds_ord_list) return self.media_list + self.attribute_list + \ self.source_list + add_list diff --git a/src/gen/lib/ldsordbase.py b/src/gen/lib/ldsordbase.py index d56e7e8b0..4f96af719 100644 --- a/src/gen/lib/ldsordbase.py +++ b/src/gen/lib/ldsordbase.py @@ -68,7 +68,7 @@ class LdsOrdBase(object): """ Convert a serialized tuple of data to an object """ - self.lds_ord_list = [LdsOrd().unserialize(item) for item in data] + self.lds_ord_list = map(LdsOrd().unserialize, data) def add_lds_ord(self, lds_ord): """ diff --git a/src/gen/lib/mediabase.py b/src/gen/lib/mediabase.py index bab305d35..fa1ddb819 100644 --- a/src/gen/lib/mediabase.py +++ b/src/gen/lib/mediabase.py @@ -48,11 +48,7 @@ class MediaBase(object): :param source: Object used to initialize the new object :type source: MediaBase """ - - if source: - self.media_list = [ MediaRef(mref) for mref in source.media_list ] - else: - self.media_list = [] + self.media_list = map(MediaRef, source.media_list) if source else [] def serialize(self): """ @@ -64,7 +60,7 @@ class MediaBase(object): """ Convert a serialized tuple of data to an object. """ - self.media_list = [MediaRef().unserialize(item) for item in data] + self.media_list = map(MediaRef().unserialize, data) def add_media_reference(self, media_ref): """ diff --git a/src/gen/lib/notebase.py b/src/gen/lib/notebase.py index 6f46e412f..06c6c5f87 100644 --- a/src/gen/lib/notebase.py +++ b/src/gen/lib/notebase.py @@ -44,11 +44,7 @@ class NoteBase(object): :param source: Object used to initialize the new object :type source: NoteBase """ - - if source: - self.note_list = [handle for handle in source.note_list] - else: - self.note_list = [] + self.note_list = list(source.note_list) if source else [] def serialize(self): """ @@ -60,7 +56,7 @@ class NoteBase(object): """ Convert a serialized tuple of data to an object. """ - self.note_list = [handle for handle in data] + self.note_list = list(data) def add_note(self, handle): """ diff --git a/src/gen/lib/person.py b/src/gen/lib/person.py index d5a068991..27d086e42 100644 --- a/src/gen/lib/person.py +++ b/src/gen/lib/person.py @@ -309,7 +309,7 @@ class Person(SourceBase, NoteBase, AttributeBase, MediaBase, :rtype: list """ check_list = self.lds_ord_list - add_list = [item for item in check_list if item] + add_list = filter(None, check_list) return [self.primary_name] + self.media_list + \ self.alternate_names + self.address_list + \ self.attribute_list + self.urls + \ diff --git a/src/gen/lib/src.py b/src/gen/lib/src.py index 908a8df9d..db17c4fd5 100644 --- a/src/gen/lib/src.py +++ b/src/gen/lib/src.py @@ -82,7 +82,7 @@ class Source(MediaBase, NoteBase, PrimaryObject): self.marker.unserialize(marker) NoteBase.unserialize(self, note_list) MediaBase.unserialize(self, media_list) - self.reporef_list = [RepoRef().unserialize(rr) for rr in reporef_list] + self.reporef_list = map(RepoRef().unserialize, reporef_list) def _has_handle_reference(self, classname, handle): """ diff --git a/src/gen/lib/srcbase.py b/src/gen/lib/srcbase.py index 78d6b8445..bd35c8fbf 100644 --- a/src/gen/lib/srcbase.py +++ b/src/gen/lib/srcbase.py @@ -48,10 +48,8 @@ class SourceBase(object): :param source: Object used to initialize the new object :type source: SourceBase """ - if source: - self.source_list = [SourceRef(sref) for sref in source.source_list] - else: - self.source_list = [] + + self.source_list = map(SourceRef, source.source_list) if source else [] def serialize(self): """ @@ -63,7 +61,7 @@ class SourceBase(object): """ Convert a serialized tuple of data to an object. """ - self.source_list = [SourceRef().unserialize(item) for item in data] + self.source_list = map(SourceRef().unserialize, data) def add_source_reference(self, src_ref) : """ diff --git a/src/gen/lib/urlbase.py b/src/gen/lib/urlbase.py index fcdd4cc6b..7a85fffc3 100644 --- a/src/gen/lib/urlbase.py +++ b/src/gen/lib/urlbase.py @@ -51,11 +51,7 @@ class UrlBase(object): :param source: Object used to initialize the new object :type source: UrlBase """ - - if source: - self.urls = [ Url(url) for url in source.urls ] - else: - self.urls = [] + self.urls = map(Url, source.urls) if source else [] def serialize(self): """ @@ -67,7 +63,7 @@ class UrlBase(object): """ Convert a serialized tuple of data to an object. """ - self.urls = [Url().unserialize(item) for item in data] + self.urls = map(Url().unserialize, data) def get_url_list(self): """ diff --git a/src/gen/proxy/private.py b/src/gen/proxy/private.py index 02ca5c21a..9f456c42c 100644 --- a/src/gen/proxy/private.py +++ b/src/gen/proxy/private.py @@ -377,7 +377,7 @@ class PrivateProxyDb(ProxyDbBase): Note that this is a generator function, it returns a iterator for use in loops. If you want a list of the results use: - > result_list = [i for i in find_backlink_handles(handle)] + > result_list = list(find_backlink_handles(handle)) """ # This isn't done yet because it doesn't check if references are diff --git a/src/gui/editors/editfamily.py b/src/gui/editors/editfamily.py index fb392da7f..41a04022e 100644 --- a/src/gui/editors/editfamily.py +++ b/src/gui/editors/editfamily.py @@ -250,7 +250,7 @@ class ChildEmbedList(EmbeddedList): self.call_edit_childref(ref.ref) def run(self, skip): - skip_list = [ x for x in skip if x] + skip_list = filter(None, skip) SelectPerson(self.dbstate, self.uistate, self.track, _("Select Child"), skip=skip_list) @@ -655,7 +655,7 @@ class EditFamily(EditPrimary): self.phandles = [mhandle, fhandle] + \ [ x.ref for x in self.obj.get_child_ref_list()] - self.phandles = [handle for handle in self.phandles if handle] + self.phandles = filter(None, self.phandles) def _create_tabbed_pages(self): diff --git a/src/gui/pluginmanager.py b/src/gui/pluginmanager.py index fce44ca8b..4d521e467 100644 --- a/src/gui/pluginmanager.py +++ b/src/gui/pluginmanager.py @@ -114,8 +114,7 @@ class GuiPluginManager(gen.utils.Callback): Note that config will then emit a signal """ self.__hidden_plugins.add(id) - hideset = [x for x in self.__hidden_plugins] - config.set('plugin.hiddenplugins', hideset) + config.set('plugin.hiddenplugins', list(self.__hidden_plugins)) config.save() self.__hidden_changed() @@ -124,8 +123,7 @@ class GuiPluginManager(gen.utils.Callback): return it again, and write this change to the config """ self.__hidden_plugins.remove(id) - hideset = [x for x in self.__hidden_plugins] - config.set('plugin.hiddenplugins', hideset) + config.set('plugin.hiddenplugins', list(self.__hidden_plugins)) config.save() self.__hidden_changed() diff --git a/src/gui/views/treemodels/familymodel.py b/src/gui/views/treemodels/familymodel.py index c973a42d6..ec33f4c54 100644 --- a/src/gui/views/treemodels/familymodel.py +++ b/src/gui/views/treemodels/familymodel.py @@ -129,7 +129,7 @@ class FamilyModel(FlatBaseModel): return unicode(gen.lib.FamilyRelType(data[5])) def column_marriage(self, data): - erlist = [ gen.lib.EventRef().unserialize(d) for d in data[6] ] + erlist = map(gen.lib.EventRef().unserialize, data[6]) erlist = [x for x in erlist if x.get_role()==EventRoleType.FAMILY or x.get_role()==EventRoleType.PRIMARY] event = self.db.marriage_from_eventref_list(erlist) @@ -139,7 +139,7 @@ class FamilyModel(FlatBaseModel): return u'' def sort_marriage(self, data): - erlist = [ gen.lib.EventRef().unserialize(d) for d in data[6] ] + erlist = map(gen.lib.EventRef().unserialize, data[6]) event = self.db.marriage_from_eventref_list(erlist) if event: return "%09d" % event.date.get_sort_value() diff --git a/src/plugins/export/ExportGedcom.py b/src/plugins/export/ExportGedcom.py index cb8695e2b..1f2547928 100644 --- a/src/plugins/export/ExportGedcom.py +++ b/src/plugins/export/ExportGedcom.py @@ -873,7 +873,7 @@ class GedcomWriter(UpdateCallback): event to discover the event type. """ - for event_ref in [ ref for ref in family.get_event_ref_list()]: + for event_ref in family.get_event_ref_list(): event = self.dbase.get_event_from_handle(event_ref.ref) etype = int(event.get_type()) val = libgedcom.familyConstantEvents.get(etype) diff --git a/src/plugins/gramplet/AgeStats.py b/src/plugins/gramplet/AgeStats.py index 1501a0f8b..32bad170a 100644 --- a/src/plugins/gramplet/AgeStats.py +++ b/src/plugins/gramplet/AgeStats.py @@ -83,9 +83,9 @@ class AgeStatsGramplet(Gramplet): age_dict = {} mother_dict = {} father_dict = {} - age_handles = [[] for age in range(self.max_age)] - mother_handles = [[] for age in range(self.max_mother_diff)] - father_handles = [[] for age in range(self.max_father_diff)] + age_handles = [[]] * self.max_age + mother_handles = [[]] * self.max_mother_diff + father_handles = [[]] * self.max_father_diff text = "" count = 0 for p in self.dbstate.db.iter_people(): diff --git a/src/plugins/gramplet/FanChartGramplet.py b/src/plugins/gramplet/FanChartGramplet.py index d7fbb271f..f66b8c321 100644 --- a/src/plugins/gramplet/FanChartGramplet.py +++ b/src/plugins/gramplet/FanChartGramplet.py @@ -143,7 +143,7 @@ class FanChartWidget(gtk.Widget): self.data = {} for i in range(self.generations): # name, person, parents?, children? - self.data[i] = [(None, None, None, None) for j in range(2 ** i)] + self.data[i] = [(None,) * 4] * 2 ** i self.angle[i] = [] angle = 0 slice = 360.0 / (2 ** i) diff --git a/src/plugins/import/ImportGrdb.py b/src/plugins/import/ImportGrdb.py index 5356e6c0a..f627b5ffe 100644 --- a/src/plugins/import/ImportGrdb.py +++ b/src/plugins/import/ImportGrdb.py @@ -747,7 +747,7 @@ class GrampsBSDDB(DbGrdb, UpdateCallback): Note that this is a generator function, it returns a iterator for use in loops. If you want a list of the results use: - > result_list = [i for i in find_backlink_handles(handle)] + > result_list = list(find_backlink_handles(handle)) """ # Use the secondary index to locate all the reference_map entries diff --git a/src/plugins/import/ImportProGen.py b/src/plugins/import/ImportProGen.py index ddcbff66b..4f50723db 100644 --- a/src/plugins/import/ImportProGen.py +++ b/src/plugins/import/ImportProGen.py @@ -814,7 +814,7 @@ class ProgenParser(object): per_klad = recflds[per_klad_ix] per_info = recflds[per_info_ix] - note_txt = [x for x in [per_info, per_klad] if x] + note_txt = filter(None, [per_info, per_klad]) if note_txt: note = gen.lib.Note() note.set('\n'.join(note_txt)) @@ -860,7 +860,7 @@ class ProgenParser(object): source_text = recflds[birth_source_text_ix] info = recflds[birth_info_ix] if date or place or info or srcref: - desc = [x for x in [info, time, source_text] if x] + desc = filter(None, [info, time, source_text]) desc = desc and '; '.join(desc) or None event, birth_ref = self.__create_event_and_ref(gen.lib.EventType.BIRTH, desc, date, place, srcref) person.set_birth_ref(birth_ref) @@ -883,7 +883,7 @@ class ProgenParser(object): source_text = recflds[bapt_source_text_ix] info = recflds[bapt_info_ix] if date or place or info or srcref or reli or witness: - desc = [x for x in [reli, info, source_text] if x] + desc = filter(None, [reli, info, source_text]) desc = desc and '; '.join(desc) or None event, bapt_ref = self.__create_event_and_ref(gen.lib.EventType.BAPTISM, desc, date, place, srcref) person.add_event_ref(bapt_ref) @@ -919,7 +919,7 @@ class ProgenParser(object): source_text = recflds[death_source_text_ix] info = recflds[death_info_ix] if date or place or info or srcref: - desc = [x for x in [info, time, source_text] if x] + desc = filter(None, [info, time, source_text]) desc = desc and '; '.join(desc) or None event, death_ref = self.__create_event_and_ref(gen.lib.EventType.DEATH, desc, date, place, srcref) person.set_death_ref(death_ref) @@ -940,7 +940,7 @@ class ProgenParser(object): source_text = recflds[bur_source_text_ix] info = recflds[bur_info_ix] if date or place or info or srcref: - desc = [x for x in [info, source_text] if x] + desc = filter(None, [info, source_text]) desc = desc and '; '.join(desc) or None event, burial_ref = self.__create_event_and_ref(gen.lib.EventType.BURIAL, desc, date, place, srcref) person.add_event_ref(burial_ref) @@ -962,7 +962,7 @@ class ProgenParser(object): info = recflds[crem_info_ix] if date or place or info or srcref: # TODO. Check that not both burial and cremation took place. - desc = [x for x in [info, source_text] if x] + desc = filter(None, [info, source_text]) desc = desc and '; '.join(desc) or None event, cremation_ref = self.__create_event_and_ref(gen.lib.EventType.CREMATION, desc, date, place, srcref) person.add_event_ref(cremation_ref) @@ -1074,7 +1074,7 @@ class ProgenParser(object): rel_klad = recflds[rel_klad_ix] rel_info = recflds[rel_info_ix] - note_txt = [x for x in [rel_info, rel_klad] if x] + note_txt = filter(None, [rel_info, rel_klad]) if note_txt: note = gen.lib.Note() note.set('\n'.join(note_txt)) @@ -1095,7 +1095,7 @@ class ProgenParser(object): source_text = recflds[mar_source_text_ix] info = recflds[mar_info_ix] if date or place or info or srcref: - desc = [x for x in [info, source_text] if x] + desc = filter(None, [info, source_text]) desc = desc and '; '.join(desc) or None event, mar_ref = self.__create_event_and_ref(gen.lib.EventType.MARRIAGE, desc, date, place, srcref) fam.add_event_ref(mar_ref) @@ -1127,7 +1127,7 @@ class ProgenParser(object): source_text = recflds[marc_source_text_ix] info = recflds[marc_info_ix] if date or place or info or srcref: - desc = [x for x in [reli, info, source_text] if x] + desc = filter(None, [reli, info, source_text]) desc.insert(0, 'Kerkelijk huwelijk') desc = desc and '; '.join(desc) or None event, marc_ref = self.__create_event_and_ref(gen.lib.EventType.MARRIAGE, desc, date, place, srcref) @@ -1159,7 +1159,7 @@ class ProgenParser(object): source_text = recflds[marl_source_text_ix] info = recflds[marl_info_ix] if date or place or info or srcref: - desc = [x for x in [info, source_text] if x] + desc = filter(None, [info, source_text]) desc.insert(0, 'Ondertrouw') desc = desc and '; '.join(desc) or None event, marl_ref = self.__create_event_and_ref(gen.lib.EventType.MARR_LIC, desc, date, place, srcref) @@ -1187,7 +1187,7 @@ class ProgenParser(object): source_text = recflds[civu_source_text_ix] info = recflds[civu_info_ix] if date or place or info or srcref: - desc = [x for x in [info, source_text] if x] + desc = filter(None, [info, source_text]) desc.insert(0, 'Samenwonen') desc = desc and '; '.join(desc) or None event, civu_ref = self.__create_event_and_ref(gen.lib.EventType.UNKNOWN, desc, date, place, srcref) @@ -1211,7 +1211,7 @@ class ProgenParser(object): source_text = recflds[div_source_text_ix] info = recflds[div_info_ix] if date or place or info or srcref: - desc = [x for x in [info, source_text] if x] + desc = filter(None, [info, source_text]) desc = desc and '; '.join(desc) or None event, div_ref = self.__create_event_and_ref(gen.lib.EventType.DIVORCE, desc, date, place, srcref) fam.add_event_ref(div_ref) diff --git a/src/plugins/lib/libgrdb.py b/src/plugins/lib/libgrdb.py index c7371b502..81fa631b8 100644 --- a/src/plugins/lib/libgrdb.py +++ b/src/plugins/lib/libgrdb.py @@ -1248,7 +1248,7 @@ class DbGrdb(Callback): """ Return the defined names that have been assigned to a default grouping. """ - return [unicode(k) for k in self.name_group.keys()] + return map(unicode, self.name_group.keys()) def has_name_group_key(self, name): """ @@ -2504,7 +2504,7 @@ class DbGrdb(Callback): Note that this is a generator function, it returns a iterator for use in loops. If you want a list of the results use: - > result_list = [i for i in find_backlink_handles(handle)] + > result_list = list(find_backlink_handles(handle)) """ # Make a dictionary of the functions and classes that we need for diff --git a/src/plugins/tool/ChangeNames.py b/src/plugins/tool/ChangeNames.py index 4def28b80..3c118789b 100644 --- a/src/plugins/tool/ChangeNames.py +++ b/src/plugins/tool/ChangeNames.py @@ -219,7 +219,7 @@ class ChangeNames(Tool.BatchTool, ManagedWindow.ManagedWindow): self.show() def toggled(self,cell,path_string): - path = tuple([int (i) for i in path_string.split(':')]) + path = tuple(map(int, path_string.split(':'))) row = self.model[path] row[0] = not row[0] diff --git a/src/plugins/tool/ExtractCity.py b/src/plugins/tool/ExtractCity.py index 925f53e8d..4f8c7ba10 100644 --- a/src/plugins/tool/ExtractCity.py +++ b/src/plugins/tool/ExtractCity.py @@ -578,7 +578,7 @@ class ExtractCity(Tool.BatchTool, ManagedWindow.ManagedWindow): return def toggled(self, cell, path_string): - path = tuple([int (i) for i in path_string.split(':')]) + path = tuple(map(int, path_string.split(':'))) row = self.model[path] row[0] = not row[0] diff --git a/src/plugins/tool/PatchNames.py b/src/plugins/tool/PatchNames.py index afd915a87..1f1ee68d8 100644 --- a/src/plugins/tool/PatchNames.py +++ b/src/plugins/tool/PatchNames.py @@ -190,7 +190,7 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow): return (self.label, None) def toggled(self, cell, path_string): - path = tuple([int (i) for i in path_string.split(':')]) + path = tuple(map(int, path_string.split(':'))) row = self.model[path] row[0] = not row[0] self.model.row_changed(path, row.iter) diff --git a/src/plugins/tool/RemoveUnused.py b/src/plugins/tool/RemoveUnused.py index 55128685e..4713bf633 100644 --- a/src/plugins/tool/RemoveUnused.py +++ b/src/plugins/tool/RemoveUnused.py @@ -309,7 +309,7 @@ class RemoveUnused(Tool.Tool, ManagedWindow.ManagedWindow, UpdateCallback): self.db.request_rebuild() def selection_toggled(self, cell, path_string): - sort_path = tuple([int (i) for i in path_string.split(':')]) + sort_path = tuple(map(int, path_string.split(':'))) real_path = self.sort_model.convert_path_to_child_path(sort_path) row = self.real_model[real_path] row[RemoveUnused.MARK_COL] = not row[RemoveUnused.MARK_COL] diff --git a/src/plugins/tool/Verify.py b/src/plugins/tool/Verify.py index 151ff7ae7..a4cdf2cf0 100644 --- a/src/plugins/tool/Verify.py +++ b/src/plugins/tool/Verify.py @@ -254,7 +254,7 @@ class Verify(Tool.Tool, ManagedWindow, UpdateCallback): self.top.connect_signals({ "destroy_passed_object" : self.close, "on_help_clicked" : self.on_help_clicked, - "on_verify_ok_clicked" : self.on_apply_clicked + "on_verify_ok_clicked" : self.on_apply_clicked, "on_delete_event" : self.close, }) @@ -562,7 +562,7 @@ class VerifyResults(ManagedWindow): button.set_label(_("_Hide marked")) def selection_toggled(self,cell,path_string): - sort_path = tuple([int (i) for i in path_string.split(':')]) + sort_path = tuple(map(int, path_string.split(':'))) filt_path = self.sort_model.convert_path_to_child_path(sort_path) real_path = self.filt_model.convert_path_to_child_path(filt_path) row = self.real_model[real_path] diff --git a/src/plugins/view/fanchartview.py b/src/plugins/view/fanchartview.py index dd3211c82..649f8e3fb 100644 --- a/src/plugins/view/fanchartview.py +++ b/src/plugins/view/fanchartview.py @@ -158,7 +158,7 @@ class FanChartWidget(gtk.Widget): self.data = {} for i in range(self.generations): # name, person, parents?, children? - self.data[i] = [(None, None, None, None) for j in range(2 ** i)] + self.data[i] = [(None,) * 4] * 2 ** i self.angle[i] = [] angle = 0 slice = 360.0 / (2 ** i) diff --git a/src/web/libdjango.py b/src/web/libdjango.py index ac138fa63..84fb44a0c 100644 --- a/src/web/libdjango.py +++ b/src/web/libdjango.py @@ -171,7 +171,7 @@ class DjangoInterface(object): else: return gen.lib.Name().serialize() else: - return [self.pack_name(name) for name in names] + return map(self.pack_name, names) def get_datamap(self, obj): # obj is source datamap_dict = {} @@ -202,10 +202,10 @@ class DjangoInterface(object): obj_type = ContentType.objects.get_for_model(obj) reporefs = models.RepositoryRef.objects.filter(object_id=obj.id, object_type=obj_type) - return [self.pack_repository_ref(repo) for repo in reporefs] + return map(self.pack_repository_ref, reporefs) def get_url_list(self, obj): - return [self.pack_url(url) for url in obj.url_set.all().order_by("order")] + return map(self.pack_url, obj.url_set.all().order_by("order")) def get_address_list(self, obj, with_parish): # person or repository addresses = obj.address_set.all().order_by("order") @@ -257,12 +257,12 @@ class DjangoInterface(object): def get_person_ref_list(self, person): obj_type = ContentType.objects.get_for_model(person) - return [self.pack_person_ref(x) for x in + return map(self.pack_person_ref, models.PersonRef.objects.filter(object_id=person.id, - object_type=obj_type)] + object_type=obj_type)) def get_lds_list(self, obj): # person or family - return [self.pack_lds(lds) for lds in obj.lds_set.all().order_by("order")] + return map(self.pack_lds, obj.lds_set.all().order_by("order")) def get_place_handle(self, obj): # obj is event if obj.place: diff --git a/src/web/utils.py b/src/web/utils.py index 94a43bafe..b4b7aa89b 100644 --- a/src/web/utils.py +++ b/src/web/utils.py @@ -162,7 +162,7 @@ class Table(object): self.table.columns(*args) def row(self, *args): - self.table.row(*[nbsp(arg) for arg in args]) + self.table.row(*map(nbsp, args)) def link(self, object_type_name, handle): self.table.set_link_col((object_type_name, handle)) diff --git a/test/GrampsDb/GrampsDbBase_Test.py b/test/GrampsDb/GrampsDbBase_Test.py index cb6c51e8c..7d2d6099d 100644 --- a/test/GrampsDb/GrampsDbBase_Test.py +++ b/test/GrampsDb/GrampsDbBase_Test.py @@ -33,7 +33,7 @@ class ReferenceMapTest (GrampsDbBaseTest): source = self._add_source() person = self._add_person_with_sources([source]) - references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ] + references = list(self._db.find_backlink_handles(source.get_handle())) assert len(references) == 1 assert references[0] == (gen.lib.Person.__name__,person.get_handle()) @@ -44,7 +44,7 @@ class ReferenceMapTest (GrampsDbBaseTest): repos = self._add_repository() source = self._add_source(repos=repos) - references = [ ref for ref in self._db.find_backlink_handles(repos.get_handle()) ] + references = list(self._db.find_backlink_handles(repos.get_handle())) assert len(references) == 1 assert references[0] == (gen.lib.Source.__name__,source.get_handle()) @@ -61,7 +61,7 @@ class ReferenceMapTest (GrampsDbBaseTest): self._add_media_object_with_sources([source]) # make sure that we have the correct number of references (one for each object) - references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ] + references = list(self._db.find_backlink_handles(source.get_handle())) assert len(references) == 5, "len(references) == %s " % str(len(references)) @@ -71,8 +71,8 @@ class ReferenceMapTest (GrampsDbBaseTest): assert references[0][0] == gen.lib.Person.__name__, "references = %s" % repr(references) # should just return the person and event reference - references = [ ref for ref in self._db.find_backlink_handles(source.get_handle(),(gen.lib.Person.__name__, - gen.lib.Event.__name__)) ] + references = list(self._db.find_backlink_handles(source.get_handle(), + (gen.lib.Person.__name__, gen.lib.Event.__name__))) assert len(references) == 2, "len(references) == %s " % str(len(references)) assert references[0][0] == gen.lib.Person.__name__, "references = %s" % repr(references) assert references[1][0] == gen.lib.Event.__name__, "references = %s" % repr(references) @@ -94,7 +94,7 @@ class ReferenceMapTest (GrampsDbBaseTest): assert self._db.get_person_from_handle(person.get_handle()) is None - references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ] + references = list(self._db.find_backlink_handles(source.get_handle())) assert len(references) == 0, "len(references) == %s " % str(len(references)) @@ -115,7 +115,7 @@ class ReferenceMapTest (GrampsDbBaseTest): person = self._add_person_with_sources([source]) # Check that the reference map does not contain the reference. - references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ] + references = list(self._db.find_backlink_handles(source.get_handle())) assert len(references) == 0, "len(references) == %s " % str(len(references)) @@ -124,7 +124,7 @@ class ReferenceMapTest (GrampsDbBaseTest): self._db.reindex_reference_map(cb) # Check that the reference now appears in the reference_map - references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ] + references = list(self._db.find_backlink_handles(source.get_handle())) assert len(references) == 1, "len(references) == %s " % str(len(references)) @@ -155,7 +155,7 @@ class ReferenceMapTest (GrampsDbBaseTest): cur.close() start = time.time() - references = [ ref for ref in self._db.find_backlink_handles(handle) ] + references = list(self._db.find_backlink_handles(handle)) end = time.time() with_reference_map = end - start @@ -165,7 +165,7 @@ class ReferenceMapTest (GrampsDbBaseTest): self._db.__class__.find_backlink_handles = self._db.__class__.__base__.find_backlink_handles start = time.time() - references = [ ref for ref in self._db.find_backlink_handles(handle) ] + references = list(self._db.find_backlink_handles(handle)) end = time.time() without_reference_map = end - start