comparison mercurial/util.py @ 31393:8b6927eb7efd

util: don't use mutable default argument value I don't think this is any tight loops and we'd need to worry about PyObject creation overhead. Also, I'm pretty sure strptime() will be much slower than PyObject creation (date parsing is surprisingly slow).
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 12 Mar 2017 21:54:32 -0700
parents 6e59397b08d8
children 7409eb69731f
comparison
equal deleted inserted replaced
31392:6168d4b93634 31393:8b6927eb7efd
1825 minutes = int(s[-2:]) 1825 minutes = int(s[-2:])
1826 return -sign * (hours * 60 + minutes) * 60, s[:-6] 1826 return -sign * (hours * 60 + minutes) * 60, s[:-6]
1827 1827
1828 return None, s 1828 return None, s
1829 1829
1830 def strdate(string, format, defaults=[]): 1830 def strdate(string, format, defaults=None):
1831 """parse a localized time string and return a (unixtime, offset) tuple. 1831 """parse a localized time string and return a (unixtime, offset) tuple.
1832 if the string cannot be parsed, ValueError is raised.""" 1832 if the string cannot be parsed, ValueError is raised."""
1833 defaults = defaults or []
1834
1833 # NOTE: unixtime = localunixtime + offset 1835 # NOTE: unixtime = localunixtime + offset
1834 offset, date = parsetimezone(string) 1836 offset, date = parsetimezone(string)
1835 1837
1836 # add missing elements from defaults 1838 # add missing elements from defaults
1837 usenow = False # default to using biased defaults 1839 usenow = False # default to using biased defaults