@@ -60,14 +60,14 @@ def _days_in_month(year, month):
6060
6161def _days_before_month (year , month ):
6262 "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 } "
6464 return _DAYS_BEFORE_MONTH [month ] + (month > 2 and _is_leap (year ))
6565
6666def _ymd2ord (year , month , day ):
6767 "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 } "
6969 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 } "
7171 return (_days_before_year (year ) +
7272 _days_before_month (year , month ) +
7373 day )
@@ -512,7 +512,7 @@ def _parse_isoformat_time(tstr):
512512def _isoweek_to_gregorian (year , week , day ):
513513 # Year is bounded this way because 9999-12-31 is (9999, 52, 5)
514514 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 } " )
516516
517517 if not 0 < week < 53 :
518518 out_of_range = True
@@ -561,21 +561,21 @@ def _check_utc_offset(name, offset):
561561 raise TypeError ("tzinfo.%s() must return None "
562562 "or timedelta, not '%s'" % (name , type (offset )))
563563 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__ () } " )
567567
568568def _check_date_fields (year , month , day ):
569569 year = _index (year )
570570 month = _index (month )
571571 day = _index (day )
572572 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 } " )
574574 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 } " )
576576 dim = _days_in_month (year , month )
577577 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 } " )
579579 return year , month , day
580580
581581def _check_time_fields (hour , minute , second , microsecond , fold ):
@@ -584,15 +584,15 @@ def _check_time_fields(hour, minute, second, microsecond, fold):
584584 second = _index (second )
585585 microsecond = _index (microsecond )
586586 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 } " )
588588 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 } " )
590590 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 } " )
592592 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 } " )
594594 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 } " )
596596 return hour , minute , second , microsecond , fold
597597
598598def _check_tzinfo_arg (tz ):
@@ -2419,7 +2419,7 @@ def __new__(cls, offset, name=_Omitted):
24192419 if not cls ._minoffset <= offset <= cls ._maxoffset :
24202420 raise ValueError ("offset must be a timedelta "
24212421 "strictly between -timedelta(hours=24) and "
2422- "timedelta(hours=24). " )
2422+ f "timedelta(hours=24), not { offset . __repr__ () } " )
24232423 return cls ._create (offset , name )
24242424
24252425 def __init_subclass__ (cls ):
0 commit comments