MCPcopy Index your code
hub / github.com/python/cpython / fromisoformat

Method fromisoformat

Lib/_pydatetime.py:1049–1064  ·  view source on GitHub ↗

Construct a date from a string in ISO 8601 format.

(cls, date_string)

Source from the content-addressed store, hash-verified

1047
1048 @classmethod
1049 def fromisoformat(cls, date_string):
1050 """Construct a date from a string in ISO 8601 format."""
1051
1052 if not isinstance(date_string, str):
1053 raise TypeError('Argument must be a str')
1054
1055 if not date_string.isascii():
1056 raise ValueError('Argument must be an ASCII str')
1057
1058 if len(date_string) not in (7, 8, 10):
1059 raise ValueError(f'Invalid isoformat string: {date_string!r}')
1060
1061 try:
1062 return cls(*_parse_isoformat_date(date_string))
1063 except Exception:
1064 raise ValueError(f'Invalid isoformat string: {date_string!r}')
1065
1066 @classmethod
1067 def fromisocalendar(cls, year, week, day):

Calls 3

_parse_isoformat_dateFunction · 0.85
isasciiMethod · 0.80
clsClass · 0.50