Skip to content

Commit e8c1d3b

Browse files
kmario23sdispater
authored andcommitted
replace old style string formatting with new format (#5)
* replace old style string formatting with new format * update parenthesis mismatch * update parenthesis mismatch
1 parent 974ce46 commit e8c1d3b

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

pendulum/pendulum.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def parse(cls, time=None, tz=pytz.UTC):
222222
dt = dateparser.parse(time)
223223

224224
if not dt:
225-
raise PendulumException('Invalid time string "%s"' % time)
225+
raise PendulumException('Invalid time string "{}"'.format(time))
226226

227227
return cls(
228228
dt.year, dt.month, dt.day,
@@ -867,7 +867,7 @@ def format_locale(cls, locale):
867867
"""
868868
m = re.match('([a-z]{2})[-_]([a-z]{2})', locale, re.I)
869869
if m:
870-
return '%s_%s' % (m.group(1).lower(), m.group(2).lower())
870+
return '{}_{}'.format(m.group(1).lower(), m.group(2).lower())
871871
else:
872872
return locale.lower()
873873

@@ -942,7 +942,7 @@ def _strftime(self, m):
942942
else:
943943
return {1: 'st', 2: 'nd', 3: 'rd'}.get(self.day % 10, "th")
944944

945-
raise ValueError('Unknown formatter %%%s' % fmt)
945+
raise ValueError('Unknown formatter %%{}'.format(fmt))
946946

947947
def __str__(self):
948948
if self._to_string_format is None:
@@ -1936,9 +1936,9 @@ def start_of(self, unit):
19361936
:rtype: Pendulum
19371937
"""
19381938
if unit not in self._MODIFIERS_VALID_UNITS:
1939-
raise ValueError('Invalid unit "%s" for start_of()' % unit)
1939+
raise ValueError('Invalid unit "{}" for start_of()'.format(unit))
19401940

1941-
return getattr(self, '_start_of_%s' % unit)()
1941+
return getattr(self, '_start_of_{}'.format(unit))()
19421942

19431943
def end_of(self, unit):
19441944
"""
@@ -2148,9 +2148,9 @@ def first_of(self, unit, day_of_week=None):
21482148
:rtype: Pendulum
21492149
"""
21502150
if unit not in ['month', 'quarter', 'year']:
2151-
raise PendulumException('Invalid unit "%s" for first_of()' % unit)
2151+
raise PendulumException('Invalid unit "{}" for first_of()'.format(unit))
21522152

2153-
return getattr(self, '_first_of_%s' % unit)(day_of_week)
2153+
return getattr(self, '_first_of_{}'.format(unit))(day_of_week)
21542154

21552155
def last_of(self, unit, day_of_week=None):
21562156
"""
@@ -2169,9 +2169,9 @@ def last_of(self, unit, day_of_week=None):
21692169
:rtype: Pendulum
21702170
"""
21712171
if unit not in ['month', 'quarter', 'year']:
2172-
raise PendulumException('Invalid unit "%s" for first_of()' % unit)
2172+
raise PendulumException('Invalid unit "{}" for first_of()'.format(unit))
21732173

2174-
return getattr(self, '_last_of_%s' % unit)(day_of_week)
2174+
return getattr(self, '_last_of_{}'.format(unit))(day_of_week)
21752175

21762176
def nth_of(self, unit, nth, day_of_week):
21772177
"""
@@ -2193,12 +2193,12 @@ def nth_of(self, unit, nth, day_of_week):
21932193
:rtype: Pendulum
21942194
"""
21952195
if unit not in ['month', 'quarter', 'year']:
2196-
raise PendulumException('Invalid unit "%s" for first_of()' % unit)
2196+
raise PendulumException('Invalid unit "{}" for first_of()'.format(unit))
21972197

2198-
dt = getattr(self, '_nth_of_%s' % unit)(nth, day_of_week)
2198+
dt = getattr(self, '_nth_of_{}'.format(unit))(nth, day_of_week)
21992199
if dt is False:
2200-
raise PendulumException('Unable to find occurence %d of %s in %s'
2201-
% (nth, self._days[day_of_week], unit))
2200+
raise PendulumException('Unable to find occurence {} of {} in {}'.format(
2201+
nth, self._days[day_of_week], unit))
22022202

22032203
return dt
22042204

@@ -2440,7 +2440,7 @@ def _get_datetime(self, value, pendulum=False):
24402440

24412441
return d._datetime
24422442

2443-
raise ValueError('Invalid datetime "%s"' % value)
2443+
raise ValueError('Invalid datetime "{}"'.format(value))
24442444

24452445
def for_json(self):
24462446
"""

pendulum/translator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _do_load_catalogue(self, locale):
3232
)
3333
else:
3434
if not self.register_resource(locale):
35-
raise NotFoundResourceException('Resource for locale "%s" could not be found' % locale)
35+
raise NotFoundResourceException('Resource for locale "{}" could not be found'.format(locale))
3636

3737
self._do_load_catalogue(locale)
3838

@@ -48,7 +48,7 @@ def register_resource(self, locale):
4848
load_module('lang', root)
4949

5050
# Loading locale
51-
locale_mod = load_module('lang.%s' % locale, locale_file)
51+
locale_mod = load_module('lang.{}'.format(locale), locale_file)
5252

5353
self.add_resource('dict', locale_mod.translations, locale)
5454

tests/pendulum_tests/test_getters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,4 @@ def is_same_day(self):
202202
def is_day_of_week(self):
203203
for i in Pendulum._days.values():
204204
d = Pendulum.now().next(getattr(Pendulum, i.upper()))
205-
self.assertTrue(getattr(d, 'is_%s' % i.lower())())
205+
self.assertTrue(getattr(d, 'is_{}s'.format(i.lower()))())

0 commit comments

Comments
 (0)