Construct a date from a string in ISO 8601 format.
(cls, date_string)
| 1038 | |
| 1039 | @classmethod |
| 1040 | def fromisoformat(cls, date_string): |
| 1041 | """Construct a date from a string in ISO 8601 format.""" |
| 1042 | |
| 1043 | if not isinstance(date_string, str): |
| 1044 | raise TypeError('Argument must be a str') |
| 1045 | |
| 1046 | if not date_string.isascii(): |
| 1047 | raise ValueError('Argument must be an ASCII str') |
| 1048 | |
| 1049 | if len(date_string) not in (7, 8, 10): |
| 1050 | raise ValueError(f'Invalid isoformat string: {date_string!r}') |
| 1051 | |
| 1052 | try: |
| 1053 | return cls(*_parse_isoformat_date(date_string)) |
| 1054 | except Exception: |
| 1055 | raise ValueError(f'Invalid isoformat string: {date_string!r}') |
| 1056 | |
| 1057 | @classmethod |
| 1058 | def fromisocalendar(cls, year, week, day): |