@@ -60,14 +60,14 @@ def _days_in_month(year, month):
60
60
61
61
def _days_before_month (year , month ):
62
62
"year, month -> number of days in year preceding first day of month."
63
- assert 1 <= month <= 12 , ' month must be in 1..12'
63
+ assert 1 <= month <= 12 , f" month must be in 1..12, but got { month } "
64
64
return _DAYS_BEFORE_MONTH [month ] + (month > 2 and _is_leap (year ))
65
65
66
66
def _ymd2ord (year , month , day ):
67
67
"year, month, day -> ordinal, considering 01-Jan-0001 as day 1."
68
- assert 1 <= month <= 12 , ' month must be in 1..12'
68
+ assert 1 <= month <= 12 , f" month must be in 1..12, but got { month } "
69
69
dim = _days_in_month (year , month )
70
- assert 1 <= day <= dim , ( ' day must be in 1..%d' % dim )
70
+ assert 1 <= day <= dim , f" day must be in 1..{ dim } , but got { day } "
71
71
return (_days_before_year (year ) +
72
72
_days_before_month (year , month ) +
73
73
day )
@@ -512,7 +512,7 @@ def _parse_isoformat_time(tstr):
512
512
def _isoweek_to_gregorian (year , week , day ):
513
513
# Year is bounded this way because 9999-12-31 is (9999, 52, 5)
514
514
if not MINYEAR <= year <= MAXYEAR :
515
- raise ValueError (f"Year is out of range: { year } " )
515
+ raise ValueError (f"year must be in { MINYEAR } .. { MAXYEAR } , but got { year } " )
516
516
517
517
if not 0 < week < 53 :
518
518
out_of_range = True
@@ -561,21 +561,21 @@ def _check_utc_offset(name, offset):
561
561
raise TypeError ("tzinfo.%s() must return None "
562
562
"or timedelta, not '%s'" % (name , type (offset )))
563
563
if not - timedelta (1 ) < offset < timedelta (1 ):
564
- raise ValueError ("%s()=%s, must be strictly between "
565
- "-timedelta(hours=24) and timedelta(hours=24)" %
566
- ( name , offset ) )
564
+ raise ValueError ("offset must be a timedelta "
565
+ "strictly between -timedelta(hours=24) and "
566
+ f"timedelta(hours=24), not { offset . __repr__ () } " )
567
567
568
568
def _check_date_fields (year , month , day ):
569
569
year = _index (year )
570
570
month = _index (month )
571
571
day = _index (day )
572
572
if not MINYEAR <= year <= MAXYEAR :
573
- raise ValueError (' year must be in %d..%d' % ( MINYEAR , MAXYEAR ), year )
573
+ raise ValueError (f" year must be in { MINYEAR } .. { MAXYEAR } , but got { year } " )
574
574
if not 1 <= month <= 12 :
575
- raise ValueError (' month must be in 1..12' , month )
575
+ raise ValueError (f" month must be in 1..12, but got { month } " )
576
576
dim = _days_in_month (year , month )
577
577
if not 1 <= day <= dim :
578
- raise ValueError (' day must be in 1..%d' % dim , day )
578
+ raise ValueError (f" day must be in 1..{ dim } , but got { day } " )
579
579
return year , month , day
580
580
581
581
def _check_time_fields (hour , minute , second , microsecond , fold ):
@@ -584,15 +584,15 @@ def _check_time_fields(hour, minute, second, microsecond, fold):
584
584
second = _index (second )
585
585
microsecond = _index (microsecond )
586
586
if not 0 <= hour <= 23 :
587
- raise ValueError (' hour must be in 0..23' , hour )
587
+ raise ValueError (f" hour must be in 0..23, but got { hour } " )
588
588
if not 0 <= minute <= 59 :
589
- raise ValueError (' minute must be in 0..59' , minute )
589
+ raise ValueError (f" minute must be in 0..59, but got { minute } " )
590
590
if not 0 <= second <= 59 :
591
- raise ValueError (' second must be in 0..59' , second )
591
+ raise ValueError (f" second must be in 0..59, but got { second } " )
592
592
if not 0 <= microsecond <= 999999 :
593
- raise ValueError (' microsecond must be in 0..999999' , microsecond )
593
+ raise ValueError (f" microsecond must be in 0..999999, but got { microsecond } " )
594
594
if fold not in (0 , 1 ):
595
- raise ValueError (' fold must be either 0 or 1' , fold )
595
+ raise ValueError (f" fold must be either 0 or 1, but got { fold } " )
596
596
return hour , minute , second , microsecond , fold
597
597
598
598
def _check_tzinfo_arg (tz ):
@@ -2419,7 +2419,7 @@ def __new__(cls, offset, name=_Omitted):
2419
2419
if not cls ._minoffset <= offset <= cls ._maxoffset :
2420
2420
raise ValueError ("offset must be a timedelta "
2421
2421
"strictly between -timedelta(hours=24) and "
2422
- "timedelta(hours=24). " )
2422
+ f "timedelta(hours=24), not { offset . __repr__ () } " )
2423
2423
return cls ._create (offset , name )
2424
2424
2425
2425
def __init_subclass__ (cls ):
0 commit comments