Mercurial > pyarq-presupuestos
diff Generic/base.py @ 22:7bd4ca56607d
bug fix: Mutable default arguments
author | Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es> |
---|---|
date | Tue, 30 Sep 2014 17:16:50 +0200 |
parents | a7b9f7e7dfa4 |
children | 65e7ae0d0e63 |
line wrap: on
line diff
--- a/Generic/base.py Sun Sep 14 17:23:02 2014 +0200 +++ b/Generic/base.py Tue Sep 30 17:16:50 2014 +0200 @@ -3,7 +3,7 @@ ## File base.py ## This file is part of pyArq-Presupuestos. ## -## Copyright (C) 2010-2013 Miguel Ángel Bárcena Rodríguez +## Copyright (C) 2010-2014 Miguel Ángel Bárcena Rodríguez ## <miguelangel@obraencurso.es> ## ## pyArq-Presupuestos is free software: you can redistribute it and/or modify @@ -259,8 +259,8 @@ Description: Record object Constructor: - base.Record(code, synonyms, hierarchy, unit, summary, prices, type, - subtype, text="") + base.Record(decimals, code, synonyms, hierarchy, unit, summary, + prices, type_, subtype, parents=None, text=None) Ancestry: +-- object +-- Record @@ -333,15 +333,19 @@ self.__labels = tuple[11] def __init__(self, decimals, code, synonyms, hierarchy, unit, summary, - prices, type_, subtype, parents=[], text=""): + prices, type_, subtype, parents=None, text=None): self.code = code self.synonyms = synonyms self.recordType = (hierarchy, type_, subtype) self.unit = unit self.summary = summary self.setPrices(prices, decimals) + if parents is None: + parents = [] self.parents = parents self.children = [] + if text is None: + text = "" self.text = text self.sheet = Sheet() self.files = [] @@ -543,9 +547,9 @@ self.__children = children def appendChild(self, child_code, decimals, factor=0.0, yield_=0.0, - measure=0.0, measure_list=[], type_ ="", label=""): + measure=0.0, measure_list=None, type_=None, label=None): """appendChildren(self, child_code, factor=0.0, yield_=0.0, - measure=0.0, measure_list=[], type_ ="", label="")) + measure=0.0, measure_list=None, type_=None, label=None)) position: child_code: @@ -558,6 +562,12 @@ Append a child to the list of children """ + if measure_list is None: + measure_list = [] + if type_ is None: + type_ = "" + if label is None: + label = "" _measure = Measure(decimals, self.recordType, measure, [], label, factor, yield_) if len(measure_list) > 0: @@ -719,8 +729,8 @@ Description: Parametric Record object Constructor: - base.ParametricRecord(code, synonyms, hierarchy, unit, summary, prices, - type_, subtype, text="") + base.ParametricRecord(budget, code, synonyms, hierarchy, unit, summary, + prices, type_, subtype, parents=None, text=None) Ancestry: +-- object +-- Record @@ -776,9 +786,13 @@ self.__parametric_text = tuple[19] def __init__(self, budget, code, synonyms, hierarchy, unit, summary, - prices, type_, subtype, parents=[], text=""): + prices, type_, subtype, parents=None, text=None): + if parents is None: + parents = [] + if text is None: + text = "" Record.__init__(self, budget, code, synonyms, hierarchy, unit, summary, - prices, type_, subtype, parents=[], text="") + prices, type_, subtype, parents, text) self.__parameters = {} self.__select_comment = "" self.__vars = {} @@ -1105,7 +1119,7 @@ """) def buildMeasure(self, list_lines, type_, decimals, recordType): - """setMeasure(self, list_lines, type_, decimals) + """setMeasure(list_lines, type_, decimals, recordType) list_lines: list of measure lines [ [linetype, comment, units, length, width, height, formula], ... ] @@ -1950,14 +1964,18 @@ def iter(self): for record in self.__records: yield record - def iterPreOrder(self, recordCode, codes=[]): + def iterPreOrder(self, recordCode, codes=None): + if codes is None: + codes = [] _children = self.getchildren(recordCode) for _child in _children: if not _child in codes: codes.append(_child) self.iterPreOrder(_child, codes) return codes - def iterPostOrder(self, recordCode, codes=[]): + def iterPostOrder(self, recordCode, codes=None): + if codes is None: + codes = [] _children = self.getchildren(recordCode) for _child in _children: if not _child in codes: @@ -2133,7 +2151,7 @@ dictionary["DIRC"], dictionary["DCD"], dictionary["DIVISA"]) self.__decimals[N] = decimals - def getDecimals(self, decimal="All", N=None): + def getDecimals(self, decimal=None, N=None): """getDecimals(self,decimal="All",N=None) decimal: @@ -2143,6 +2161,7 @@ N: the price group None,1,2,.. None: Return the active price group """ + if decimal is None: decimal = "All" if N is None: N = self.getActiveTitle() if decimal == "All": return self.__decimals[N+1] @@ -2172,14 +2191,16 @@ "IVA" : dictionary["IVA"]} self.__percentages = _percentages - def getPercentages(self, key="All"): - """getPercentages(self, percentage="All") + def getPercentages(self, key=None): + """getPercentages(self, key=None) key: "All": Return the Percentages dictionary "keys": Return the keys of a Percentages object key: Return a Percentages value for the key """ + if Key is None: + key = "All" if key == "All": return self.__percentages elif key == "keys":