Changeset - 122323853d5a
[Not reviewed]
0 2 0
Brett Smith - 6 years ago 2017-12-19 14:13:44
brettcsmith@brettcsmith.org
importers: Prefer using ChainMaps to copying and updating dicts.
2 files changed with 9 insertions and 11 deletions:
0 comments (0 inline, 0 general)
import2ledger/importers/_csv.py
Show inline comments
 
import collections
 
import csv
 

	
 
class CSVImporterBase:
...
 
@@ -27,16 +28,15 @@ class CSVImporterBase:
 

	
 
    def __init__(self, input_file):
 
        self.in_csv = csv.DictReader(input_file)
 
        self.entry_seed = self.ENTRY_SEED.copy()
 
        self.entry_seed = {}
 

	
 
    def __iter__(self):
 
        for row in self.in_csv:
 
            row_data = self._read_row(row)
 
            if row_data is not None:
 
                retval = self.entry_seed.copy()
 
                retval.update(
 
                    (entry_key, row[row_key])
 
                copied_fields = {
 
                    entry_key: row[row_key]
 
                    for row_key, entry_key in self.COPIED_FIELDS.items()
 
                )
 
                retval.update(row_data)
 
                yield retval
 
                }
 
                yield collections.ChainMap(
 
                    row_data, copied_fields, self.entry_seed, self.ENTRY_SEED)
import2ledger/importers/nbpy2017.py
Show inline comments
 
import collections
 
import decimal
 
import functools
 

	
...
 
@@ -110,10 +111,7 @@ class Invoice2017:
 
            self.actions.append(action)
 

	
 
    def __iter__(self):
 
        for action in self.actions:
 
            data = self.base_data.copy()
 
            data.update(action)
 
            yield data
 
        return (collections.ChainMap(act, self.base_data) for act in self.actions)
 

	
 

	
 
@functools.lru_cache(5)
0 comments (0 inline, 0 general)