99import time as _time
1010import math as _math
1111import sys
12+
13+ import warnings
1214from operator import index as _index
1315
1416def _cmp (x , y ):
@@ -452,7 +454,7 @@ def _parse_hh_mm_ss_ff(tstr):
452454
453455 return time_comps
454456
455- def _parse_isoformat_time (tstr ):
457+ def _parse_isoformat_time (tstr , is_expanded = False ):
456458 # Format supported is HH[:MM[:SS[.fff[fff]]]][+HH:MM[:SS[.ffffff]]]
457459 len_str = len (tstr )
458460 if len_str < 2 :
@@ -493,6 +495,14 @@ def _parse_isoformat_time(tstr):
493495 if len (tzstr ) in (0 , 1 , 3 ) or tstr [tz_pos - 1 ] == 'Z' :
494496 raise ValueError ("Malformed time zone string" )
495497
498+ if is_expanded and ":" not in tzstr and len (tzstr ) > 2 :
499+ import warnings
500+ warnings .warn (
501+ "Support for partially expanded formats are deprecated in "
502+ "accordance with ISO 8601:2 and will be removed in 3.15" ,
503+ DeprecationWarning
504+ )
505+
496506 tz_comps = _parse_hh_mm_ss_ff (tzstr )
497507
498508 if all (x == 0 for x in tz_comps ):
@@ -1933,6 +1943,11 @@ def fromisoformat(cls, date_string):
19331943 # Split this at the separator
19341944 try :
19351945 separator_location = _find_isoformat_datetime_separator (date_string )
1946+ if separator_location != len (date_string ) and date_string [separator_location ] != 'T' :
1947+ import warnings
1948+ warnings .warn ("Support of date/time separators other than "
1949+ "[\" T\" ] is deprecated in accordance with ISO "
1950+ "8601:2 and will be removed in 3.15" , DeprecationWarning )
19361951 dstr = date_string [0 :separator_location ]
19371952 tstr = date_string [(separator_location + 1 ):]
19381953
@@ -1943,7 +1958,10 @@ def fromisoformat(cls, date_string):
19431958
19441959 if tstr :
19451960 try :
1946- time_components , became_next_day , error_from_components = _parse_isoformat_time (tstr )
1961+ is_expanded = date_string [4 ] == "-"
1962+ time_components , became_next_day , error_from_components = (
1963+ _parse_isoformat_time (tstr , is_expanded )
1964+ )
19471965 except ValueError :
19481966 raise ValueError (
19491967 f'Invalid isoformat string: { date_string !r} ' ) from None
0 commit comments