@@ -92,10 +92,7 @@ def _get_dt_and_tzinfo(dt_or_tzinfo: _DtOrTzinfo) -> tuple[datetime.datetime | N
9292 tzinfo = UTC
9393 elif isinstance (dt_or_tzinfo , (datetime .datetime , datetime .time )):
9494 dt = _get_datetime (dt_or_tzinfo )
95- if dt .tzinfo is not None :
96- tzinfo = dt .tzinfo
97- else :
98- tzinfo = UTC
95+ tzinfo = dt .tzinfo if dt .tzinfo is not None else UTC
9996 else :
10097 dt = None
10198 tzinfo = dt_or_tzinfo
@@ -150,7 +147,7 @@ def _get_datetime(instant: _Instant) -> datetime.datetime:
150147 """
151148 if instant is None :
152149 return datetime .datetime .utcnow ()
153- elif isinstance (instant , int ) or isinstance ( instant , float ):
150+ elif isinstance (instant , ( int , float ) ):
154151 return datetime .datetime .utcfromtimestamp (instant )
155152 elif isinstance (instant , datetime .time ):
156153 return datetime .datetime .combine (datetime .date .today (), instant )
@@ -615,10 +612,7 @@ def get_timezone_name(
615612 zone_variant = 'generic'
616613 else :
617614 dst = tzinfo .dst (dt )
618- if dst :
619- zone_variant = 'daylight'
620- else :
621- zone_variant = 'standard'
615+ zone_variant = "daylight" if dst else "standard"
622616 else :
623617 if zone_variant not in ('generic' , 'standard' , 'daylight' ):
624618 raise ValueError ('Invalid zone variation' )
@@ -629,9 +623,8 @@ def get_timezone_name(
629623 return zone
630624 info = locale .time_zones .get (zone , {})
631625 # Try explicitly translated zone names first
632- if width in info :
633- if zone_variant in info [width ]:
634- return info [width ][zone_variant ]
626+ if width in info and zone_variant in info [width ]:
627+ return info [width ][zone_variant ]
635628
636629 metazone = get_global ('meta_zones' ).get (zone )
637630 if metazone :
@@ -1088,15 +1081,14 @@ def format_interval(
10881081 # > single date using availableFormats, and return.
10891082
10901083 for field in PATTERN_CHAR_ORDER : # These are in largest-to-smallest order
1091- if field in skel_formats :
1092- if start_fmt .extract (field ) != end_fmt .extract (field ):
1093- # > If there is a match, use the pieces of the corresponding pattern to
1094- # > format the start and end datetime, as above.
1095- return "" .join (
1096- parse_pattern (pattern ).apply (instant , locale )
1097- for pattern , instant
1098- in zip (skel_formats [field ], (start , end ))
1099- )
1084+ if field in skel_formats and start_fmt .extract (field ) != end_fmt .extract (field ):
1085+ # > If there is a match, use the pieces of the corresponding pattern to
1086+ # > format the start and end datetime, as above.
1087+ return "" .join (
1088+ parse_pattern (pattern ).apply (instant , locale )
1089+ for pattern , instant
1090+ in zip (skel_formats [field ], (start , end ))
1091+ )
11001092
11011093 # > Otherwise, format the start and end datetime using the fallback pattern.
11021094
@@ -1235,10 +1227,7 @@ def parse_date(
12351227 # names, both in the requested locale, and english
12361228
12371229 year = numbers [indexes ['Y' ]]
1238- if len (year ) == 2 :
1239- year = 2000 + int (year )
1240- else :
1241- year = int (year )
1230+ year = 2000 + int (year ) if len (year ) == 2 else int (year )
12421231 month = int (numbers [indexes ['M' ]])
12431232 day = int (numbers [indexes ['D' ]])
12441233 if month > 12 :
@@ -1285,9 +1274,8 @@ def parse_time(
12851274 # Check if the format specifies a period to be used;
12861275 # if it does, look for 'pm' to figure out an offset.
12871276 hour_offset = 0
1288- if 'a' in format_str :
1289- if 'pm' in string .lower ():
1290- hour_offset = 12
1277+ if 'a' in format_str and 'pm' in string .lower ():
1278+ hour_offset = 12
12911279
12921280 # Parse up to three numbers from the string.
12931281 minute = second = 0
@@ -1490,10 +1478,7 @@ def format_weekday(self, char: str = 'E', num: int = 4) -> str:
14901478 num = 3
14911479 weekday = self .value .weekday ()
14921480 width = {3 : 'abbreviated' , 4 : 'wide' , 5 : 'narrow' , 6 : 'short' }[num ]
1493- if char == 'c' :
1494- context = 'stand-alone'
1495- else :
1496- context = 'format'
1481+ context = "stand-alone" if char == "c" else "format"
14971482 return get_day_names (width , context , self .locale )[weekday ]
14981483
14991484 def format_day_of_year (self , num : int ) -> str :
0 commit comments